0
votes

Please could u let me know how i can add dynamic starting position and ending position together in a range .

so basically i have Range("A3:D" & lastRow)

i want something like below .

Range("A:D" &firstrow, & lastRow)

Here the firstrow and last row will be specified by me

1
Possible duplicate of Error in finding last used cell in VBAifo20
Selecting the start and stop of a range is static not dynamic. Why not just use `Range("A5:D10").Select'?GMalc
@ifo20, The question is not clear, I don't think the OP is asking how to find the last row. In the last sentence the OP is wanting to specify the start and stop rows for his range in columns A:D, which is basically asking how to write Range("A5:D10").GMalc

1 Answers

2
votes

Did you try something like this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim firstRow As Integer
    Dim lastRow As Integer
    Dim rng As String

    firstRow = 5
    lastRow = 10
    rng = "A" & CStr(firstRow) & ":" & "D" & CStr(lastRow)
    ActiveSheet.Range(rng).Select
End Sub