Using a variable for row in (row,column) for a range in VBA

后端 未结 1 1938
死守一世寂寞
死守一世寂寞 2020-12-12 07:16

I have a global variable called processRowBegin that contains the row number for the beginning of a process. I also have a global variable called processRowEnd that contains

相关标签:
1条回答
  • 2020-12-12 07:54

    You would do it this way:

    Range("C" & processRowBegin & ":C" & processRowEnd).Select
    

    Range takes either two cells or a string to denote the extents.

    To do it by the two cells:

    Range(Cells(processRowBegin,3),Cells(processRowEnd,3)).Select
    

    A couple notes:

    1. One should avoid using select and simply do what is desired with the cells. For more information on how to avoid it see this POST

    2. One should always qualify all all range objects to their parent sheets. If using the Cells() they too need to be qualified

    Example

    With WorkSheets("Sheet1")
        .Range(.Cells(processRowBegin,3),.Cells(processRowEnd,3)).Value = .Range(.Cells(processRowBegin,5),.Cells(processRowEnd,5)).Value
    End With
    
    0 讨论(0)
提交回复
热议问题