Excel VBA : Range gives Argument Not Optional error message

标签 excel vba range

在 Excel vba 中,我尝试选择从单元格“O2”(O 来自 Oyster)开始到工作表末尾的一系列值, 我正在尝试:

 Range("O2", Range.End(xlDown))

但是失败了,并出现参数不可选。我究竟做错了什么? 我使用的是 Excel 2010。

最佳答案

不要使用 xlDown 声明您的对象,然后使用它。

使用这个

Option Explicit

Sub Sample()
    Dim ws As Worksheet
    Dim LRow As Long
    Dim rng As Range

    '~~> Change this to the relevant sheet name
    Set ws = ThisWorkbook.Sheets("Sheet1")

    With ws
        '~~> Find last row in Col O which has data
        LRow = .Range("O" & .Rows.Count).End(xlUp).Row

        '~~> This is your range
        Set rng = .Range("O2:O" & LRow)

        With rng
            '~~> Whatever you want to do
        End With
    End With
End Sub

关于Excel VBA : Range gives Argument Not Optional error message,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20706585/

相关文章:

vba - 如何将一系列 For 循环 block 缩短为一个

swift - 在 Swift 中推进范围内的所有元素?

python - xlsxwriter: text_wrap() 不工作

excel - 选择txt作为输出后如何保存对话

c# - 在 VSTO 中配置 log4net

vba - "if not instr"无法像我想象的那样在 vba 中工作

excel - 按日期锁定 Excel 列

python - 我想打印以奇数或偶数作为索引的字母(字符串)并将它们保存为列表

Swift - `范围最小 - 最大范围内的数字

php - 性能/负载测试 PHP/Coldfusion 电子表格 Web 处理?