【问题标题】:I want the code to return a string, but it is returning a value我希望代码返回一个字符串,但它正在返回一个值
【发布时间】: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

标签: excel vba inputbox


【解决方案1】:

您的代码当前获取 rng 单元格的值。要获取 rng 单元格的地址,请调用单元格的 Address 属性,如下所示:

MsgBox rng.address

【讨论】:

    猜你喜欢
    • 2013-08-17
    • 1970-01-01
    • 2018-08-12
    • 1970-01-01
    • 1970-01-01
    • 2010-10-16
    • 2021-11-11
    • 1970-01-01
    • 2013-11-12
    相关资源
    最近更新 更多