View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Macro-if condition met-copy and paste row to new sheet

Give this macro a try (change the two Set statements for the Source and
Destination workbooks as appropriate)...

Sub CopyRowsWithNumbersInB()
Dim X As Long
Dim LastRow As Long
Dim Source As Worksheet
Dim Destination As Worksheet
Dim RowsWithNumbers As Range
Set Source = Worksheets("Sheet1")
Set Destination = Worksheets("Sheet2")
With Source
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
For X = 2 To LastRow
If IsNumeric(.Cells(X, "B").Value) And .Cells(X, "B").Value < "" Then
If RowsWithNumbers Is Nothing Then
Set RowsWithNumbers = .Cells(X, "B")
Else
Set RowsWithNumbers = Union(RowsWithNumbers, .Cells(X, "B"))
End If
End If
Next
If Not RowsWithNumbers Is Nothing Then
RowsWithNumbers.EntireRow.Copy Destination.Range("A1")
End If
End With
End Sub

--
Rick (MVP - Excel)


"ScottMSP" wrote in message
...
Hello,

I have a worksheet that has in column B either numbers, the word "Enter",
or
it could be empty. If the cell in column B has a number, it will also
have a
data in that row (Column A - AH).

I need a macro that will look at column B to see if there is a number in
any
of the cells of column b and if so, I need the macro to copy the data in
that
row (columns A - AH) and paste just those rows into a new worksheet.

So for instance, let's say I have 10 rows. In column B, rows 6 - 8 have
numbers; row 9 and 10 has the word "Enter"; row 11 and 12 is empty; and
row
13 - 15 have numbers. I need to take only those rows that have numbers in
columin B (6-8 and 13-15) and copy the entire row (columns A-AH) and paste
the data into a new worksheet.

Thanks in advance.