Need help merging to macros (IF / OR Statement)

scatki

New Member
Joined
Oct 21, 2015
Messages
7
Hi,

I'm hoping someone can help me with the code to combine the two macros below. They are identical except for the color boxes they are looking for. I'm looking for one macro to clear both the red and green boxes.

Thanks in advance or anyone that has a look!

-------------------------------------------------------------------------

Sub DeleteRedBox()

Dim shp As Shape

'Loop through each shape on active sheet

For Each shp In ActiveSheet.Shapes

'Find shapes with a name starting with "RedBox_"

If Left(shp.Name, 7) = "RedBox_" Then

'Delete the shape

shp.Delete

End If

Next shp

End Sub

-----------------------------------------------------------


Sub DeleteGreenBox()

Dim shp As Shape

'Loop through each shape on active sheet

For Each shp In ActiveSheet.Shapes

'Find shapes with a name starting with "GreenBox_"

If Left(shp.Name, 9) = "GreenBox_" Then

'Delete the shape

shp.Delete

End If

Next shp

End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Have you tried:

VBA Code:
If Left(shp.Name, 7) = "RedBox_" Or Left(shp.Name, 9) = "GreenBox_" Then
 
Upvote 0
Solution
Thank you Kevin, that's it! I really appreciate your help.
As you also confirmed, the solution post is supposed to be #2. Therefore, I switched the marked solution accordingly.

In your future questions, please mark the post as the solution that answered your question to help future readers.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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