I'm trying to take data from a previous sheet and trying to filter it by zip codes by going row by row. I'll copy the selected row that fit the right zip code and paste it onto a new sheet. However, my 2nd for loop is not running after the first. Since I'm new to VBA I'm not sure if I'm ending it right or not or there is a faster way by nesting but I can't think of a way. Explanation would be great to know what is going on.
Here is my code so far:
Here is my code so far:
Code:
Sub Remove_Unwanted_Columns_and_Rows()
Dim wb1 As Workbook 'Declarations
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim ws3 As Worksheet 'Add Last Worksheet
Dim LastrowA As Integer
Set ws2 = ActiveWorkbook.Sheets.Add(After:=Worksheets(Worksheets.Count))
ws2.Name = "Reformed"
Application.ScreenUpdating = False 'Turn off screen updating to increase performance
LastrowA = ThisWorkbook.Sheets("Data").Cells(Rows.Count, 1).End(xlUp).Row 'Find the last row on active sheet
'BEGIN FILTERING
'1st Filter
Set ws3 = ActiveWorkbook.Sheets.Add(After:=Worksheets(Worksheets.Count))
ws3.Name = "Filtered"
Dim i As Integer 'counter
Sheets("Filtered").Select
Range("A1").Value = "1st Area"
Range("A1").Font.Bold = True
For i = 2 To LastrowA
Sheets("Reformed").Select
Range("F" & i).Select 'Select column F for Zips
check_zip = ActiveCell
If check_zip = "98745" Then
ActiveCell.EntireRow.Copy 'Copy entire row
Sheets("Filtered").Select
RowCount = Cells(Cells.Rows.Count, "A").End(xlUp).Row 'Count rows for new sheet
Range("A" & RowCount + 1).Select
ActiveSheet.Paste
Sheets("Reformed").Select
End If
Next i
'2nd Area Filter
Sheets("Filtered").Select
Area2 = Cells(Cells.Rows.Count, "A").End(xlUp).Row ' Count for placement for next Area Title
Range("a" & Area2 + 1).Value = "2nd area"
Range("a" & Area2 + 1).Font.Bold = True
Sheets("Filtered").Select
ActiveSheet.Columns.AutoFit
For j = 2 To LastrowA
Sheets("Reformed").Select
Range("F" & i).Select
check_zip2 = ActiveCell
If check_zip2 = "96857" Then
Active.Cell.EntireRow.Copy
Sheets("Filtered").Select
RowsCount2 = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Range("A" & RowCount2 + 1).Select
ActiveSheet.Paste
Sheets("Reformed").Select
End If
Next j
Sheets("Filtered").Select
Area3 = Cells(Cells.Rows.Count, "A").End(xlUp).Row ' Count for placement for next Area Title
Range("a" & Area2 + 1).Value = "Local"
Range("a" & Area2 + 1).Font.Bold = True
End Sub