我有一个非常简单的问题,不幸的是我无法解决。因此,将感谢您的帮助。事情是这样的:
我应该从范围中获取最后一列作为范围。例如,如果我有 A26:D32,我应该得到 D26:D32 作为结果并输入到循环中。
这是我到目前为止的代码:
Function getSmth(CustomCol As Range)
Dim i As Double
For Each cell In CustomCol 'start of the loop. CustomCol here should return D26:D32 already
If cell.Value > i Then
i = cell.Value
End If
Next
....
End Function
我试图做的是编写 CustomCol.Columns(6),因为我知道最后一列,但它没有成功。
真的很高兴得到您的帮助!
最佳答案
你可以试试这个:
Function GetLasRangeCol(rng As Range) As Range
Set GetLasRangeCol = rng.Columns(rng.Columns.Count).Cells
End Function
您可以在调用代码中将其用作:
For Each cell In GetLasRangeCol(myRange)
其中‘myRange’是一个有效的范围引用,即:要么是 Range 类型的变量,要么是某个 Range 对象(如‘Range(“A5:B21”)’)以获取最后一列
关于excel - VBA,如何获取最后一列作为给定范围内的范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52135419/