Msg Box If Row contains trigger word

somesoldiers

Board Regular
Joined
Feb 23, 2008
Messages
199
Hi Guys

I would like a Msg Box to pop up if Row G or Row K contain the word "New" if not I want my macro to continue, having trouble with the If then, else bit, any ideas please?

Thanks

Noel
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Code:
Sub CheckNew()
if Range("G1")="New" or Range("K1")="New" then MsgBox "Found New"
 
End sub
 
Upvote 0
Try this code:
Code:
Public Sub FindNew()
Dim r As Range, rSearch As Range
Set r = Union(Columns("G:G"), Columns("K:K"))
Set rSearch = r.Find(What:="New", After:=Range("G1"), LookIn:=xlValues, Lookat:=xlWhole)
If Not rSearch Is Nothing Then
MsgBox "Found New in: " & rSearch.Address
Else
'Continue your macro here!
End If
End Sub
 
Upvote 0
Hi Guys

this code works perfect but I would like to make a slight adjustment, instead of the macro shutting down when the user selects ok, I would like the user to be given the option with another message box "Do you want to ignore?". If they select yes, macro will continue on and highlght next cell with "New" in or continue to end? if they click ignore macro will shut down.

Apprectiate any help

Thanks

Noel
 
Upvote 0
In that case, following option should work. I have commented the code all over so that you can understand the logic behind:
Code:
Public Sub FindNew()
Dim r As Range, rSearch As Range
Dim vbResult As VbMsgBoxResult
Dim firstAddress
'This creates a union of the specific columns and makes for easy reference in the code!
Set r = Union(Columns("G:G"), Columns("K:K"))
'This looks for the first instance of text "New"
Set rSearch = r.Find(What:="New", After:=Range("G1"), LookIn:=xlValues, Lookat:=xlWhole)
'If there's no cell with text "New then it will go to else
If Not rSearch Is Nothing Then
firstAddress = rSearch.Address
ContinueHere: 'See below in Case 1
'This sets an option of ignoring and going to the next cell
vbResult = MsgBox("Found New in: " & rSearch.Address _
& vbCrLf & "Do you want to ignore?", vbOKCancel, "FOUND CELL")
    
    Select Case vbResult
    Case 1 'Case Ignore
    Set rSearch = r.FindNext(rSearch)
        If rSearch.Address = firstAddress Then Exit Sub
        GoTo ContinueHere 'We'll use the same message box to avoid recursive code
    Case 2 'Case end macro
    'Continue here to end macro
    End Select
Else
'Continue here to end macro
End If
End Sub
 
Upvote 0
that's brilliant Taurean, thanks a lot for taking the time to help, will study your logic and am sure it will come in handy elsewhere
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,220
Members
452,895
Latest member
BILLING GUY

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