如何做一个动态的With reference?
How to make a dynamic With reference?
我如何制作一个动态参考sheet?
Dim lr2 As Long
Dim rng As Range
SelectedSystem = ThisWorkbook.Worksheets("Blabla").Range("AI2").Value
'I would like to change this to a version like the one below,
' where I reference the selected system rather than a specific sheet.
With Sheet2
lr2 = Worksheets("Blabla" & SelectedSystem & " Blabla").Cells(.Rows.Count, 2).End(xlUp).Row
Set rng = Worksheets("Blabla" & SelectedSystem & " Blabla").Range("H2:H" & lr2)
End With
创建一个 worksheet
对象,
所以
dim w as excel.worksheet
然后
set w=Worksheets("Blabla" & SelectedSystem & " Blabla")
然后使用with w
我如何制作一个动态参考sheet?
Dim lr2 As Long
Dim rng As Range
SelectedSystem = ThisWorkbook.Worksheets("Blabla").Range("AI2").Value
'I would like to change this to a version like the one below,
' where I reference the selected system rather than a specific sheet.
With Sheet2
lr2 = Worksheets("Blabla" & SelectedSystem & " Blabla").Cells(.Rows.Count, 2).End(xlUp).Row
Set rng = Worksheets("Blabla" & SelectedSystem & " Blabla").Range("H2:H" & lr2)
End With
创建一个 worksheet
对象,
所以
dim w as excel.worksheet
然后
set w=Worksheets("Blabla" & SelectedSystem & " Blabla")
然后使用with w