VBA Help with IF statement

sweetness34

Board Regular
Joined
Jun 23, 2011
Messages
70
Hi i need help with simple coding. I cant seem to come up with the right code for the program to understand.
here is my code
Code:
    If  ***       Then
 
Cells.Find(What:="Non-Conveyor Piping", SearchDirection:=xlNext, LookAt:=xlWhole).Select
Cells.Find(What:="Non-Conveyor Piping", After:=Range("A1"), SearchDirection:=xlPrevious).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.EntireRow.Insert shift:=xlUp
Else

what i want to happen is search the spreadsheet for "Non-Conveyor Piping" and if it exists then execute the code. if it does not, then simply ignore the code and procede.

Thanks
 
IF ***have it search for conveyor piping here and if it exists***THEN ***execute code*** ELSE ***procede***
If you are referring your original code, where you are looping through ranges on both your raw data sheet and summary sheet, that is a more complex and inefficient way of doing it. Also, as you see, when you add in too many GoTo statements, it may not work so well. Typically, I try to keep one single error handler and one GoTo statement per procedure. Anything more than that tells me my code may not be designed too well.

If your data is really set-up like you have posted in myour example, then the code should work.
Are columns C,D, and H the pertinent columns?
Does your data start on row 2?
If not, we may need to make adjustments.

If something is not working as suspected, please explain exactly what you see happening.
 
Upvote 0

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Did you solve your problem? If not, figure out a way to upload your excel file on the net and we can take a look at where your code is breaking.
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,266
Members
452,902
Latest member
Knuddeluff

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