Copy rows with specific text from multiple Worksheets to another worksheet

craigy111

New Member
Joined
Jul 5, 2017
Messages
20
HI guys.

I would like to copy rows from multiple worksheets (Jan to Dec) that contain certain text - WON, PENDING, LOST - When a VBA Button is pressed on another Worksheet the information is copied to VIEW. So far i can copy from only one worksheet at a time.

CODE so far

Sub CopyWONtoView()

Dim c As Range
Dim j As Integer
Dim Source As Worksheet
Dim Target As Worksheet

Set Source = ActiveWorkbook.Worksheets("Jan")
Set Target = ActiveWorkbook.Worksheets("VIEW")

Target.Range("$A$4:$R$50").Clear

j = 4 ' Start copying to row 4 in target sheet
For Each c In Source.Range("A4:A95")
If c = "WON" Then
Source.Rows(c.Row).Copy Target.Rows(j)
j = j + 1
End If
Next c

Worksheets("VIEW").Activate

End Sub

Any and all help would be much appreciated.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Firstly, did you remember to change the criteria from
=chr20 to =WON?
Secondly do you how to step through the code in the module?
 
Upvote 0
Yip Changed =chr20 to =WON.

Just found out how to step through the code and it would appear to search through all the
worksheets and look at the WON lines but for some reason after MARCH it stops copying
and pasting.
 
Upvote 0
Im a fool.

Got it working. I didn't notice the +1.

Final Code:

Sub CopyDatatoView()

Dim UsdRws As Long
Dim Ws As Worksheet
Dim DstSht As Worksheet

Set DstSht = ActiveWorkbook.Worksheets("VIEW")

DstSht.Rows("5:" & Rows.Count).Clear

For Each Ws In Worksheets
If Ws.Name <> "View" And Ws.Name <> "REVIEW" And Ws.Name <> "LIST" And Ws.Name <> "DATA" Then

UsdRws = Ws.Range("A" & Rows.Count).End(xlUp).Row

Ws.Range("A5").AutoFilter
Ws.Range("A5:A" & UsdRws).AutoFilter Field:=1, Criteria1:="=WON"
On Error Resume Next
Ws.Range("A6:A" & UsdRws + 1).SpecialCells(xlVisible).EntireRow.Copy _
DstSht.Range("A" & Rows.Count).End(xlUp).Offset(1)
On Error GoTo 0
Ws.Range("A5").AutoFilter
End If
Next Ws

DstSht.Activate

End Sub


Thank you very much, i owe you a pint or two :laugh:
 
Upvote 0
Bugger its running the MACRO twice before ending so its now giving me all results twice.

Any advice on this..........

I think i'm going to have to study VBA coding.
 
Upvote 0
In this line
Code:
If Ws.Name <> "View" And
View should be in caps
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,723
Messages
6,174,107
Members
452,544
Latest member
aush

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top