Error 1004, When I am trying to check a range for certain pattern

CMVasquez

New Member
Joined
Jul 29, 2017
Messages
7
Here is the code in my macro that I would like to use to check cell range D4:O4 for the pattern FY followed by two numbers. Any help would be appreciated.

If Range("D4:O4").Value <> "FY##" Then
MsgBox "please check your FY's."
End If
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi
How about
Code:
    Dim Cl As Range
    For Each Cl In Range("D4:O4")
        If Not UCase(Cl.Value) Like "FY##" Then
            MsgBox "please check your FY's."
            Exit Sub
        End If
    Next Cl
This will accept FY & fy. if you want it to be case sensitive replace the if statement with
Code:
        If Not Cl.Value Like "FY##" Then
 
Last edited:
Upvote 0
Glad to help & thanks for the feedback
 
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