【问题标题】:How do I reference a range 1 column to the right of a work range using a range variable?如何使用范围变量引用工作范围右侧的范围 1 列?
【发布时间】:2019-07-19 12:14:52
【问题描述】:

我需要处理每天都在变化的一系列单元格。我已经决定处理这个问题的最佳方法可能是使用 InputBox 来获得工作范围。宏处理数据并将其放置在 InputBox 范围右侧的 1 列中,但数据不在相邻的单元格中(如果有区别的话。)

我想选择新数据所在的选定范围右侧的单元格 1 列(这是首选解决方案)并格式化新数据。或者如果我无法选择范围,我可以选择整列,然后更改整列的格式。

我不知道如何提取范围信息以对其进行必要的数学运算,然后使用它来更改新创建数据的格式。

我已经包含了代码问题区域的简化示例。

感谢您的帮助。


Sub InputBox_Range_Test()    
    Dim rng As Range
    Set rng = Application.InputBox(Prompt:=PromptString, Type:=8)

    Debug.Print rng.Address

    '
    '*** Needs to select the range that is 
    '*** 1 column to the right of the input range
    '
    Columns(rng).Select 
    Selection.NumberFormat = "0.00%"
    Range("I4").Select
End Sub

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    我终于明白了。我想错了。我试图让它变得更难。我只需要使用 offset 属性。

    这是我想出的:


    私有子 CommandButton2_Click()

    Dim rngTarget As Range
    
    Set rngTarget = Application.InputBox(strPrompt, "Select the Range to work with", Type:=8)
    
    Range(rngTarget.Address).Offset(, 1).Select
    Selection.NumberFormat = "0.00%"
    Range("P2").Select
    

    结束子

    【讨论】:

      猜你喜欢
      • 2020-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-24
      相关资源
      最近更新 更多