on error

Lavan

Board Regular
Joined
Dec 15, 2004
Messages
56
Hello All,

I am using below code to move the data to different sheets. The problem is my data is not same always. Code is returning error if the data is not existing. Please suggest how to modify the code to move forward to next even some of the data not availble.

Thanks in advance

Sub CopyRows_new()
Dim lr As Long

'Application.ScreenUpdating = False

Sheets.Add.Name = "FA-3A Port 0"
Sheets.Add.Name = "FA-3A Port 1"
Sheets.Add.Name = "FA-3B Port 0"
Sheets.Add.Name = "FA-3B Port 1"
Sheets.Add.Name = "FA-3C Port 0"
Sheets.Add.Name = "FA-3C Port 1"


Rows(1).EntireRow.Insert
lr = Range("A" & Rows.Count).End(xlUp).Row
With Range("A1:A" & lr)
.AutoFilter Field:=1, Criteria1:="FA-3A Port 0"
.Resize(.Rows.Count - 1, 8).Offset(1).Copy _
Destination:=Sheets("FA-3A Port 0").Range("A1")
.AutoFilter
.AutoFilter Field:=1, Criteria1:="FA-3A Port 1"
.Resize(.Rows.Count - 1, 8).Offset(1).Copy _
Destination:=Sheets("FA-3A Port 1").Range("A1")
.AutoFilter
.AutoFilter Field:=1, Criteria1:="FA-3B Port 0"
.Resize(.Rows.Count - 1, 8).Offset(1).Copy _
Destination:=Sheets("FA-3B Port 0").Range("A1")
.AutoFilter
.AutoFilter Field:=1, Criteria1:="FA-3B Port 1"
.Resize(.Rows.Count - 1, 8).Offset(1).Copy _
Destination:=Sheets("FA-3B Port 1").Range("A1")
.AutoFilter
.AutoFilter Field:=1, Criteria1:="FA-3C Port 0"
.Resize(.Rows.Count - 1, 8).Offset(1).Copy _
Destination:=Sheets("FA-3C Port 0").Range("A1")
.AutoFilter
.AutoFilter Field:=1, Criteria1:="FA-3C Port 1"
.Resize(.Rows.Count - 1, 8).Offset(1).Copy _
Destination:=Sheets("FA-3C Port 1").Range("A1")
.AutoFilter


End With
Rows(1).EntireRow.Delete
Sheets("masking").Select
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Without saying why data won't be there or how you can anticipate it, try On Error Resume Next prior to the line(s) that is giving you the error(s).

HTH,

Smitty
 
Upvote 0
The data I am trying to sort to different sheets is exported from a report, So there are chances that some of the data I am trying to move to a new sheet may not present in all the reports. So my code returns error and halts when ever some data I am looking for is not present. I tried using on error resume next, it stopped returning the error but also stopped moving the data to new sheets. Please help.

Thanks,
Lavan
 
Upvote 0

Forum statistics

Threads
1,214,786
Messages
6,121,548
Members
449,038
Latest member
Guest1337

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