1
votes

How do you select a range that contains data from the row below an active cell (or row) to a specified cell in a different column?

For example, if row 7 is selected (or cell A7), I want to select all of the cells (or rows) with data from A8 to BA200.

2

2 Answers

0
votes

The Macro will always select 200 rows below the Activecell and 52 columns across

You can obviously change the parameters(i.e 200,52)

Sub Picker()
 Range(ActiveCell.Offset(200 - ActiveCell.Row, 0), ActiveCell.Offset(1, 52)).Select
End Sub
0
votes

This code will select all the cells in the specified span relative to the starting cell if they contain data (or any other criteria you want).

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