我想知道如何编写这个范围,将“G”更改为字符串变量 strColumn
.
这是我要更改的代码:
Dim lastRowElemento As Integer
lastRowElemento = Cells(Rows.Count, "G").End(xlUp).Row
Set rngElemento = ws.Range("G2:G" & lastRowElemento)
最佳答案
应用OP的方法,试试这个:
Sub TEST()
Dim ws As Worksheet, Rng As Range, sCol As String
sCol = "G"
Set ws = ThisWorkbook.Sheets("TEST") 'change as required
With ws.Columns(sCol)
Set Rng = Range(.Cells(2), .Cells(.Rows.Count).End(xlUp))
End With
End Sub
关于excel - 使用列字母的字符串变量设置范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69746215/