VBA End Sub if statement not met

mariusnielsen

New Member
Joined
Mar 12, 2011
Messages
4
I have a piece of code that I need to exit sub if criteria is not met. Not sure how to solve this with exit or end sub...Tried with else function but cannot get it to work.

Sub COPY_PARCEL_HEADER_2()

LR = Sheets("SAP MMT").Cells(Rows.Count, "C").End(xlUp).Row

myCopyRow = LR + 1

lastrow = Sheets("PARCELS").Cells(Rows.Count, "A").End(xlUp).Row

Application.ScreenUpdating = False

Sheets("SAP MMT").Cells(myCopyRow, "B") = "Parcel id:"
Sheets("SAP MMT").Cells(myCopyRow, "E") = "Gross"
Sheets("SAP MMT").Cells(myCopyRow, "G") = "Kgs"
Sheets("SAP MMT").Cells(myCopyRow, "H") = "Net"
Sheets("SAP MMT").Cells(myCopyRow, "J") = "Kgs"
Sheets("SAP MMT").Cells(myCopyRow, "K") = "Lenght "
Sheets("SAP MMT").Cells(myCopyRow, "M") = "Width "
Sheets("SAP MMT").Cells(myCopyRow, "O") = "Height "

Sheets("SAP MMT").Range("A" & myCopyRow, "P" & myCopyRow).Font.FontStyle = "Bold"

For myRow = 4 To lastrow
If Sheets("Parcels").Cells(myRow, "A") = 2 And Sheets("Parcels").Cells(myRow, "T") <> "" Then

Sheets("SAP MMT").Cells(myCopyRow, "C") = Sheets("PARCELS").Cells(myRow, "T")
Sheets("SAP MMT").Cells(myCopyRow, "F") = Sheets("PARCELS").Cells(myRow, "N")
Sheets("SAP MMT").Cells(myCopyRow, "I") = Sheets("PARCELS").Cells(myRow, "O")
Sheets("SAP MMT").Cells(myCopyRow, "L") = Sheets("PARCELS").Cells(myRow, "P")
Sheets("SAP MMT").Cells(myCopyRow, "N") = Sheets("PARCELS").Cells(myRow, "Q")
Sheets("SAP MMT").Cells(myCopyRow, "P") = Sheets("PARCELS").Cells(myRow, "R")

myCopyRow = myCopyRow + 1


End If
Next myRow

Application.ScreenUpdating = True


End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
You can put Exit Sub anywhere inside the SUB. Yes, you need to test if something is true.
If C = 1 then
Exit Sub
Elseif C = 2 then
'Do something else
end if
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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