Patrick Rinard

New Member
Joined
Jan 20, 2016
Messages
2
Hi,
So I am trying to build a macro to pull data from one sheet in a workbook sorted by the data in column M. I currently have the macro written such that it pulls all of the data over to each of the new sheets and then deleting the info that is not applicable. Unfortunately the deleting is only working of the first sheet once the macro starts running the second sheet I get an error "Run-time error ‘13’ which says Type mismatch". I am not sure what to do to get the sheets after the first one to work the same way. See below for the code as it is currently written.

Sheets("Detail Sorted").Select
Range("A2:M" & Last).Select
Selection.Copy
Sheets("FBPR").Select
Range("A2").Select
ActiveSheet.Paste
For i = 1000 To 1 Step -1
If Cells(i, "M").Value = "RBCC" Or Cells(i, "M").Value = "RBCB" Or _
Cells(i, "M").Value = "FCB" Or Cells(i, "M").Value = "STATE FARM" Or _
Cells(i, "M").Value = "VZCON" Then
Cells(i, 1).EntireRow.Delete
End If
Next i

Sheets("Detail Sorted").Select
Range("A2:M" & Last).Select
Selection.Copy
Sheets("RBCC").Select
Range("A2").Select
ActiveSheet.Paste
For i = 1000 To 1 Step -1
If Cells(i, "M").Value = "FCB" Or Cells(i, "M").Value = "RBCB" Or _
Cells(i, "M").Value = "FBPR" Or Cells(i, "M").Value = "STATE FARM" Or _
Cells(i, "M").Value = "VZCON" Then
Cells(i, 1).EntireRow.Delete
End If
Next i


For i = 1000 To 1 Step -1
If Cells(i, "M").Value = "FCB" Or "RBCB" Or "FBPR" Or "STATE FARM" Or "VZCON" Then
Cells(i, 1).EntireRow.Delete
End If
Next i




Sheets("Detail Sorted").Select
Range("A2:M" & Last).Select
Selection.Copy
Sheets("RBCB").Select
Range("A2").Select
ActiveSheet.Paste
For i = 1000 To 1 Step -1
If Cells(i, "M").Value = "FBPR" Or Cells(i, "M").Value = "RBCC" Or _
Cells(i, "M").Value = "FCB" Or Cells(i, "M").Value = "STATE FARM" Or _
Cells(i, "M").Value = "VZCON" Then
Cells(i, 1).EntireRow.Delete
End If
Next i


Sheets("Detail Sorted").Select
Range("A2:M" & Last).Select
Selection.Copy
Sheets("FCB").Select
Range("A2").Select
ActiveSheet.Paste
For i = 1000 To 1 Step -1
If Cells(i, "M").Value = "FBPR" Or Cells(i, "M").Value = "RBCC" Or _
Cells(i, "M").Value = "RBCB" Or Cells(i, "M").Value = "STATE FARM" Or _
Cells(i, "M").Value = "VZCON" Then
Cells(i, 1).EntireRow.Delete
End If
Next i




Sheets("Detail Sorted").Select
Range("A2:M" & Last).Select
Selection.Copy
Sheets("STATE FARM").Select
Range("A2").Select
ActiveSheet.Paste
For i = 1000 To 1 Step -1
If Cells(i, "M").Value = "FBPR" Or Cells(i, "M").Value = "RBCC" Or _
Cells(i, "M").Value = "RBCB" Or Cells(i, "M").Value = "FCB" Or _
Cells(i, "M").Value = "VZCON" Then
Cells(i, 1).EntireRow.Delete
End If
Next i




Sheets("Detail Sorted").Select
Range("A2:M" & Last).Select
Selection.Copy
Sheets("VZCON").Select
Range("A2").Select
ActiveSheet.Paste
For i = 1000 To 1 Step -1
If Cells(i, "M").Value = "FBPR" Or Cells(i, "M").Value = "RBCC" Or _
Cells(i, "M").Value = "RBCB" Or Cells(i, "M").Value = "FCB" Or _
Cells(i, "M").Value = "STATE FARM" Then
Cells(i, 1).EntireRow.Delete
End If
Next i
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I just figured this out. There was an error in a different part of code that we showing up here. Thanks to anyone who took a look at this.
 
Upvote 0

Forum statistics

Threads
1,216,135
Messages
6,129,075
Members
449,485
Latest member
greggy

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