我在一列中有一个值MyValue
,想要遍历之前的n
行。 Calc函数有两个参数:Calc(MyValue, n)
。它大概如下:{不幸的是,关于行和列的Debug.Print是空的。嗨显示。}
Function Calc (MyValue, n)
Dim Copyrange As String
Dim rng As Range
Dim cell As Range
Dim MyCol, MyRow, Startrow, Lastrow
Debug.Print "Hi"
Range(Valuex).Select
MyCol = Split(Selection.Address, "$")(1)
MyRow = Split(Selection.Address, "$")(2)
Debug.Print "Row is : " & MyRow
Debug.Print "Col is : " & MyCol
Startrow = MyRow - n + 1
Lastrow = MyRow
Let Copyrange = MyCol & Startrow & ":" & MyCol & Lastrow
Range(Copyrange).Select
Set rng = Application.Selection
….xxxxxxxxxxxxxxxxxx
Some loop with rng
Calc = xxxxxxxxx
End Function
答案 0 :(得分:0)
我不确定我是否理解您的代码,但我会这样写:
Function Sample(rngStart As Range, nbRows As Long)
Dim i As Long
For i = 0 To rngStart
With rngStart.Offset(-i, 0)
Debug.Print .Address, .Value
End With
Next i
End Function