vba - 使用单元格值作为

标签 vba excel

我尝试使用单元格 F2 中的值作为较大数字范围内的范围选择的最大值。

我已经了解了以下内容,但收到编译错误:变量未定义。

Option Explicit

Sub SelectByValue(Rng1 As Range, MinimunValue As Double, MaximumValue As Double)

    Dim MyRange As Range
    Dim Cell As Object

     'Check every cell in the range for matching criteria.
    For Each Cell In Rng1
        If Cell.Value >= MinimunValue And Cell.Value <= MaximumValue Then
            If MyRange Is Nothing Then
                Set MyRange = Range(Cell.Address)
            Else
                Set MyRange = Union(MyRange, Range(Cell.Address))
            End If
        End If
    Next
     'Select the new range of only matching criteria
    MyRange.Select

End Sub


Sub CallSelectByValue()

     'Call the macro and pass all the required variables to it.
     'In the line below, change the Range, Minimum Value, and Maximum Value as needed
    Call SelectByValue(Range("A2:A41"), 1, Range(F2).Value)

End Sub

最佳答案

在这一行中:

Call SelectByValue(Range("A2:A41"), 1, Range(F2).Value)

F2需要加引号。它不是代码可以看到的变量:

Call SelectByValue(Range("A2:A41"), 1, Range("F2").Value)

关于vba - 使用单元格值作为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30928097/

相关文章:

vba - 检查找到值旁边的单元格是否为空 VBA

vba - 如何使用单元格的内容作为我的代码的输入?

Excel VBA - 格式条件

vba - Excel VBA中复制时如何判断是否有隐藏列

python - 在python中请求对称矩阵

vba - Excel:每x秒重新计算一次

excel - 如果超链接断开,则将整行复制到目标工作表

add-in - C# : Excel 2007 Addin, 如何 Hook Windows 激活和停用事件

c# - 如何使用 asp.net 创建和下载 excel 文档

C# 和 Excel 互操作