【发布时间】:2021-12-13 04:35:04
【问题描述】:
我想知道如何编写这个范围,将“G”更改为字符串变量strColumn。
这是我要更改的代码:
Dim lastRowElemento As Integer
lastRowElemento = Cells(Rows.Count, "G").End(xlUp).Row
Set rngElemento = ws.Range("G2:G" & lastRowElemento)
【问题讨论】:
-
ws.Range(strColumn & "2:" & strColumn & lastRowElemento) -
到目前为止,我还没有看到或将其用作要求。您能否分享您打算应用它的代码,即应该有另一个(更好的方法)?另外,您为什么不使用第二行中的工作表参考,即
lastRowElemento = ws.Cells(ws.Rows.Count, "G").End(xlUp).Row? -
可能还有
lastRowElemento = ws.Cells(ws.Rows.Count, strColumn).End(xlUp).Row -
另一种方式:
ws.Range(ws.cells(2, strColumn ),ws.cells(lastRowElemento,strColumn)