如何选择包含活动单元格(或行)下方行到另一列中指定单元格的数据的范围?
例如,如果选择了第7行(或单元格A7),我想选择包含A8到BA200数据的所有单元格(或行)。
答案 0 :(得分:0)
宏将始终在Activecell
下方选择200行,在
你可以明显改变参数(即200,52)
Sub Picker()
Range(ActiveCell.Offset(200 - ActiveCell.Row, 0), ActiveCell.Offset(1, 52)).Select
End Sub
答案 1 :(得分:0)
如果这些代码包含数据(或您想要的任何其他条件),则此代码将选择相对于起始单元格的指定范围内的所有单元格。
Private Sub selectRangeWithData()
Dim startCell As Range
Dim dataRange As Range
Dim rowSpan As Integer, colSpan As Integer
Set startCell = Range("A7")
rowSpan = 200
colSpan = 52
'initialize the first cell of the selected range
Set dataRange = Range(startCell.Offset(1, 0).Address)
'loop through the supplied range and determine if data exists
For Each cell In Range(startCell.Offset(1, 0), startCell.Offset(rowSpan, colSpan)).Cells
If cell <> "" Then
'if so, add it to the range
Set dataRange = Union(dataRange, Range(cell.Address))
End If
Next cell
'finally, select the range of cells
dataRange.Select
End Sub