我想根据Sheet2中单元格Z1中可用的计数在Sheet3中选择特定数量的单元格。下面的代码有点帮助,但不完全。 Sheet3中的数据是一个过滤范围,我想只选择工作表3中标题列下方的可见单元格(基于Z1中提供的计数)。提前感谢!
Sheets("Sheet3").Range("A1:X" & Sheets("Sheet2").Range("Z1").Value).Select
答案 0 :(得分:0)
我认为你的标题占了一排。相应地更改HeaderRows
。私人
Sub Test()
Dim myRange As Range, HeaderRows As Long
Dim newRange As Range, myArea As Range
Set myRange = Sheets("Sheet3").Range("A1:X" & Sheets("Sheet2").Range("Z1").Value)
'Change number of rows accordingly
HeaderRows = 1
With myRange
Set myRange = .Offset(HeaderRows, 0).Resize(.Rows.Count - HeaderRows, _
.Columns.Count).SpecialCells(xlCellTypeVisible)
End With
'Loop through each visible area
Set newRange = myRange.Areas(1)
For Each myArea In myRange.Areas
'Add area to a range
Set newRange = Application.Union(myArea, newRange)
Next
'Select new range
newRange.Select
End Sub