Select a range of rows based on a column value


Posted by Dan Wilson on February 11, 2000 10:05 PM

I am trying to find an example of a simple VBA
procedure that selects a range of rows based on a
value in a column.

The VBA code will ultimately copy selected rows based on (equal to) a value in a column, and paste the selected range onto another worksheet.



Posted by Celia on February 12, 2000 5:47 PM


Dan
If my understanding is correct, you want to select and copy entire rows that contain a specified value in one of the columns. The following is one suggestion.

Let’s say you need to copy all rows that contain the value “info” in column A.
The following code is one way it can be done :-

Dim cell As Range
Dim aRange As Range
Set aRange = Range(Range("A1"), Range("A65536").End(xlUp))
For Each cell In aRange
If cell.Value <> "info" Then
cell.EntireRow.Hidden = True
End If
Next cell
aRange.SpecialCells(xlCellTypeVisible).EntireRow.Copy

After adding your code to paste the rows, the hidden rows can be unhidden by:

aRange.EntireRow.Hidden = False

Celia