在excel vba中,我试着选择从Cell"O2"开始的一系列值,(O from Oyster)直到表的末尾,我正在尝试:
Range("O2", Range.End(xlDown))
Run Code Online (Sandbox Code Playgroud)
但那失败了Argument Not Optional
.我究竟做错了什么?我正在使用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
Run Code Online (Sandbox Code Playgroud)