View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
ScottMSP ScottMSP is offline
external usenet poster
 
Posts: 34
Default Help Modifying Macro - Merge multiple sheets based on a condition

Hello,

I have the following code below. I have a total of 7 seperate worksheets
within a workbook that I want this macro to run on. Essentially I want to be
able to copy any row that has a number in column B. This macro works great
for one worksheet, but I want to be able to take all 7 sheets and combine
into one sheet.

Thanks in advance.

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("Clinical Nursing")
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