I am trying to copy specific data from each sheet in a workbook and paste it on a different sheet one after another. The number of rows is different on each sheet so i need to select only non-blank cells (and exclude formulas that result in blanks ie=""). I also need it to skip over 5 sheets as these do not have the info being requested. Sheets["SUMMARY TEMPLATE", "MILEAGE SUMMARY", "MILEAGE TRACKER", "ACTIVITY TRACKER", and "PBI DATA"]
Here is what I'd like to do:
- Loop through each worksheet except the 5 above. On each worksheet, copy all non-blank cells in range(B26:E38) and paste them on the "Activity Data" Sheet under the next blank cell.
I have tried to piece together a few different codes but none of them work together.
Please help!
I really appreciate any help, thanks!!
Here is what i have, it works when i run it on the activesheet but when i try to run it on all sheets (For each ws in Worksheets) I get a bunch of errors.
Sub a()
Dim LR As Long, cell As Range, rng As Range
Dim ws As Worksheets
For Each ws In Worksheets
With ws
LR = ws.Range("B" & Rows.Count).End(xlUp).row
If ws.Name <> "SUMMARY TEMPLATE" And ws.Name <> "MILEAGE SUMMARY" And ws.Name <> "MILEAGE TRACKER" _
And ws.Name <> "ACTIVITY TRACKER" And ws.Name <> "PBI DATA" Then
For Each cell In .Range("B26:E26" & LR)
If cell.Value <> "" Then
If rng Is Nothing Then
Set rng = cell
Else
Set rng = Union(rng, cell)
End If
End If
Next cell
rng.Select
End With
Next ws
End If
End With
Next
Selection.Copy
Sheets("ACTIVITY TRACKER").Select
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
Selection.PasteSpecial Paste:=xlPasteValues
End Sub
.Range("B26:E26" & LR)
is not.Range("B26:E" & LR)
? – Dirk Reichel