【发布时间】:2019-08-08 21:26:20
【问题描述】:
我正在尝试使用 InputBox 让用户通过单击鼠标选择起始单元格。然后我想将该地址作为字符串存储在变量中。
Sub NumberFormatFromCell()
Dim rng As Range
Dim FormatRuleInput As String
'Get A Cell Address From The User to Get Number Format From
On Error Resume Next
Set rng = Application.InputBox( _
Title:="Number Format Rule From Cell", _
Prompt:="Select a starting cell", _
Type:=8)
On Error GoTo 0
'Test to ensure User Did not cancel
If rng Is Nothing Then Exit Sub
'Set Variable to first cell in user's input (ensuring only 1 cell)
Set rng = rng.Cells(1, 1)
MsgBox (rng)
End Sub
当代码到达MsgBox(rng) 时,它会显示单元格中的值,而不是地址。
【问题讨论】:
-
MsgBox rng.address