(Solved) – VBA dynamic with reference

  • by

It would help me substantially if I could make a dynamic With -reference to a sheet. However for some reason i can’t create a dynamic reference using the With-statement. Any ideas?

Dim lr2 As Long
Dim rng As Range

SelectedSystem = ThisWorkbook.Worksheets("Blabla").Range("AI2").Value

With Sheet2 'I would like to change this to a version like the one below, where i reference the selected system rather than a specific sheet.
    lr2 = Worksheets("Blabla" & SelectedSystem & " Blabla").Cells(.Rows.Count, 2).End(xlUp).Row
    Set rng = Worksheets("Blabla" & SelectedSystem & " Blabla").Range("H2:H" & lr2)
End With

Leave a Reply

Your email address will not be published. Required fields are marked *