Excel vba - 如何在范围函数内使用变量?

Excel vba - how to use a variable inside the range function?

如何将此函数设为函数以便我可以将“B38”作为变量传递?我尝试将 'startCell' 放入 range 函数中,但它失败了,我不清楚需要什么才能使它工作...

TIA

Set startCell = Range("B38")
For i = 0 To 6
    hourVal = Worksheets("Expense & Hours").Range("b38").Offset(0, i).Value
    dateVal = Worksheets("Expense & Hours").Range("b38").Offset(2, i).Value
    MsgBox "Current: " & hourVal & "  " & dateVal
Next i

你的意思是这样?

Dim addr As String

addr = "B38"

Set startCell = Worksheets("Expense & Hours").Range(addr)
For i = 0 To 6
    hourVal = startCell.Offset(0, i).Value
    dateVal = startCell.Offset(2, i).Value
    MsgBox "Current: " & hourVal & "  " & dateVal
Next i