VBA to delete tabs based on partial text in a worksheet

borkybork

New Member
Joined
Aug 5, 2022
Messages
18
Office Version
  1. 365
Platform
  1. Windows
Hi there!

I have this code, but it only works for the 2nd and 3rd conditions. How do I add an “OR” condition to it that searches the entire workbook for a partial text and delete the worksheet if found? For example, merged cell A1:C1 = “Your one stop for Excel tips & solutions”, but I only need to find “tips & solutions” and delete any sheet that contains this phrase. Thanks in advance!

So to summarize, the goal is to delete sheets if A5 = 100 AND A6 = 1 OR A1 = “* tips & solutions” but code can’t find partial text with the wildcard symbol.

VBA Code:
Sub Delete_Worksheets

Dim ws As Worksheet
Dim i As integer

Application.DisplayAlerts = False

For each ws in ActiveWorkbook.Worksheets

If ws.range(“A1”).Value = “* tips & solutions” Or ws.range(“A5”).Value = 100 And ws.range(“A6”) = 1 Then

On Error Resume Next
ws.delete

On Error GoTo 0
End If

Next

Application.DisplayAlerts = True
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Don't have Excel ATM, so untested, but try
VBA Code:
If Instr(ws.range(“A1”), “ tips & solutions”) Or ws.range(“A5”).Value = 100 And ws.range(“A6”) = 1 Then
 
Upvote 0
Solution
Don't have Excel ATM, so untested, but try
VBA Code:
If Instr(ws.range(“A1”), “ tips & solutions”) Or ws.range(“A5”).Value = 100 And ws.range(“A6”) = 1 Then
Thanks for responding!! This worked great!!
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

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