在 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/