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

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

Leave a Comment