Simplify macro

Sumeluar

Active Member
Joined
Jun 21, 2006
Messages
271
Office Version
  1. 365
  2. 2016
  3. 2010
Platform
  1. Windows
  2. MacOS
  3. Mobile
Good day to all gurus out there, I have a find code and I want it to skip the words like search, category, Go to, etc.


Can this be simplified?
Code:
If myText = "Search" Then GoTo Litz
If myText = "search" Then GoTo Litz
If myText = "category" Then GoTo Litz
If myText = "Category" Then GoTo Litz
If myText = "Go" Then GoTo Litz
If myText = "go" Then GoTo Litz
If myText = "Go to" Then GoTo Litz
If myText = "go to" Then GoTo Litz

Regards!

Sumeluar
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try

Code:
If UCase(mytext) = "SEARCH" Or UCase(mytext) = "CATEGORY" Or UCase(mytext) = "GO" Or UCase(mytext) = "GOTO" Then GoTo Litz
 
Upvote 0
Code:
Dim myarray, j As Integer, txt As String, check As String
myarray = Array("Search", "search", "category", "Category", "Go", "go", "Go to", "go to")
    For j = LBound(myarray) To UBound(myarray)
        If txt = myarray(j) Then check = "Yes"
    Next j
    If check = "Yes" Then GoTo Litz
 
Upvote 0
Code:
If UCase(myText) = "SEARCH" or If UCase(myText) = "CATEGORY" or If UCase(myText) = "GO TO" then GoTo Litz

But you probably want to avoid using GoTo as well. Perhaps reviewing the rest of your code might be beneficial.

Hope that helps! :)
 
Upvote 0
Maybe something like this
Code:
X = Array("SEARCH","CATEGORY","GO","GOTO") 
On Error Resume Next
Y = ""
Y = WorksheetFunction.Match(Ucase(mytext),X)
If Y <> "" Then Goto Litz
 
Upvote 0
Thanks Jonmo1, That works perfect.

Regards!

Sumeluar
 
Upvote 0

Forum statistics

Threads
1,215,024
Messages
6,122,729
Members
449,093
Latest member
Mnur

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