MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Conditional select range in a macro

Posted by Leonardo on October 23, 2000 3:18 PM

i'm trying to make a macro that takes some rows and copy them to another location, but the problem is that those rows are results from a form worksheet, so i want the macro to copy only the rows that contain information, can anybody help me?

Posted by Celia on October 26, 2000 5:03 PM

The best way to do this depends upon circustances.
Here's one way that copies all the rows to the new location and then deletes the blank rows from the new location :-

Sub CopyRowsWithData()
Dim newLocation As Range, col As Range
Dim toCheck As Range, cell As Range, toDelete As Range
Set newLocation = Rows(10) 'Change the new location(Row10) to fit your requirements
Application.ScreenUpdating = False
Application.CutCopyMode = False
Set col = ActiveCell.EntireColumn
Set toCheck = Intersect(Selection, col)
For Each cell In toCheck
If Application.CountA(cell.EntireRow) = 0 Then
If toDelete Is Nothing Then
Set toDelete = cell
Set toDelete = Union(toDelete, cell)
End If
End If
End Sub