I am having trouble getting this macro to run over multiple worksheets
I have tried lost of ideas but can't get it right.
Just learning to write macros but this has me beat
Would also like to know how to restrict just to 3 or 4 columns in the Report(Stock)
This works perfectly for the sheet listed (Cap 2)
I think the lines in blue need to be changed for multiple sheets
Wayne
Sub CopyRowsWithNumbers()
' report Macro
' Macro recorded 2/23/2011
'
Dim X As Long
Dim LastRow As Long
Dim Source As Worksheet
Dim Destination As Worksheet
Dim RowsWithNumbers As Range
Set Source = Worksheets("Cap 2")
Set Destination = Worksheets("Stock")
With Source
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For X = 8 To 155
If IsNumeric(.Cells(X, "A").Value) And .Cells(X, "A").Value <> "" Then
If RowsWithNumbers Is Nothing Then
Set RowsWithNumbers = .Cells(X, "A")
Else
Set RowsWithNumbers = Union(RowsWithNumbers, .Cells(X, "A"))
End If
End If
Next
If Not RowsWithNumbers Is Nothing Then
RowsWithNumbers.EntireRow.Copy Destination.Range("A2")
End If
End With
MsgBox "Data has been updated !!", vbInformation, "Transfer Done"
End Sub
I have tried lost of ideas but can't get it right.
Just learning to write macros but this has me beat
Would also like to know how to restrict just to 3 or 4 columns in the Report(Stock)
This works perfectly for the sheet listed (Cap 2)
I think the lines in blue need to be changed for multiple sheets
Wayne
Sub CopyRowsWithNumbers()
' report Macro
' Macro recorded 2/23/2011
'
Dim X As Long
Dim LastRow As Long
Dim Source As Worksheet
Dim Destination As Worksheet
Dim RowsWithNumbers As Range
Set Source = Worksheets("Cap 2")
Set Destination = Worksheets("Stock")
With Source
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For X = 8 To 155
If IsNumeric(.Cells(X, "A").Value) And .Cells(X, "A").Value <> "" Then
If RowsWithNumbers Is Nothing Then
Set RowsWithNumbers = .Cells(X, "A")
Else
Set RowsWithNumbers = Union(RowsWithNumbers, .Cells(X, "A"))
End If
End If
Next
If Not RowsWithNumbers Is Nothing Then
RowsWithNumbers.EntireRow.Copy Destination.Range("A2")
End If
End With
MsgBox "Data has been updated !!", vbInformation, "Transfer Done"
End Sub