0

如何使它成为一个函数,以便我可以将“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
4

1 回答 1

1

你的意思是这样吗?

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
于 2021-06-15T20:03:20.770 回答