Using .Find in a Macro

storm925

Board Regular
Joined
Jan 20, 2010
Messages
226
Hello All, Here is my macro that I would like to make work more accurately...

Sub Find_Missing_Data()
On Error Resume Next
Range("A:A").Find(What:="ADD", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Select
MsgBox "No Missing Data Found."
End Sub

What I am having an issue with is that if there is an "ADD" in column A, the Message Box still comes up. I only want the message to activate if there really are no ADD's in column A. Just looking for some help on putting this together. Thank you, --Ben
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Code:
Sub Find_Missing_Data()
Dim fnd
On Error Resume Next 'you probably don't need this
Set fnd = Range("A:A").Find(What:="ADD", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If fnd Is Nothing Then MsgBox "No Missing Data Found." Else fnd.Select
End Sub
 
Upvote 0
Hi Ben,

Try this:

Code:
Sub Macro2()
    
    Dim rngFoundCell As Range
    
    Set rngFoundCell = Range("A:A").Find(What:="ADD", _
                                         LookIn:=xlValues, _
                                         LookAt:=xlWhole, _
                                         SearchOrder:=xlByRows, _
                                         SearchDirection:=xlNext, _
                                         MatchCase:=True, _
                                         SearchFormat:=False)
    
    'If the 'rngFoundCell' variable has not been set, then...
    If rngFoundCell Is Nothing Then
        '...display a message informing the user so.
        MsgBox "No Missing Data Found."
    End If
    
End Sub

Or just:

Code:
Sub Macro3()

    If Evaluate("COUNTIF(A:A,""ADD"")") = 0 Then
        MsgBox "No Missing Data Found."
    End If
    

End Sub

HTH

Robert
 
Upvote 0

Forum statistics

Threads
1,224,504
Messages
6,179,144
Members
452,891
Latest member
JUSTOUTOFMYREACH

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