Hello Everybody. First time post but long time follower of Excel and VBA posts on here. I have searched this site to help me solve this specific problem but so far I am only able to come up with the code to make this work for one condition at a time (can't replicate it for a loop).
So here is my dilemma...
I have a worksheet with a tab called "All Data" that has a column with information that matches the names of the other worksheets (tabs). What I want to be able to do is run a script that will look for and execute the following:
- VB script will look at the worksheet “All Data” and where it finds
“Column B – Reporting = No”
It will copy and paste into a tab (worksheet) that matches the name of what is in “Column C”
Do this for all districts listed in Column C. Amarillo to Paris
Ex: Found Reporting=No for Amarillo. Copy and paste all “Reporting = No” data for Amarillo into the Amarillo worksheet (tab)
Ex: Then found Reporting=No for Austin. Copy and paste all “Reporting=No” data for Austin into the Austin worksheet (tab)
So on and so on until it hits Paris and then it will stop after that
I will attach the spreadsheet but here is the code I came up with so far but it only works for one occurrence of a district's name at a time. I can't seem to figure out the coding to make it do it for all occurrences, match them up and copy/paste to their respective district's tab.
I know that a pivot table would be the easiest but for what I am trying to do, this actually makes more sense and is easier to distribute to our people.
I want to thank you all in advance for your help with this!
Private Sub Workbook_Open()
Dim i, LastRow
LastRow = Sheets("All Data").Range("A" & Rows.Count).End(xlUp).Row
Sheets("Amarillo").Range("A1:I500").ClearContents
For i = 1 To LastRow
If Sheets("All Data").Cells(i, "B").Value = "No" And Sheets("All Data").Cells(i, "C").Value = "Amarillo" Then
Sheets("All Data").Cells(i, "C").EntireRow.Copy Destination:=Sheets("Amarillo").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
End Sub
Bookmarks