VBA Syntax needed For/Do..Until/With - not sure

ARW17

Board Regular
Joined
Oct 31, 2016
Messages
109
I have the following which checks to see if the user has a personal day scheduled on the date the user input.

If txtRmvP <> [SFPersDaySch].[Form]![EventDate] Then
MsgBox "You do not have a Personal Day scheduled on this date."
End If

Right now, it’s checking the first instance and then concluding that the user does not have a Personal Day scheduled on that date. The user may have more than 1 personal days scheduled. How do I modify this to check all of the scheduled event dates before concluding that there isn’t one scheduled on that day?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi,

This would be the way I might do it:
Code:
Sub Test()
    Dim i       As Long
    Dim found   As Boolean
    
    With ThisWorkbook.Worksheets("Sheet1")
        found = False
        For i = 1 To .Cells(.Rows.Count, "A").End(xlUp).Row
            If [<condition><condition>condition] Then found = True
        Next
        If Not found Then MsgBox "You do not have a Personal Day scheduled on this date."
    End With
End Sub
Note: [condition] <condition>needs to be replaced with your actual code. Also, I assumed that the data is in column A of Sheet1

Basically, you create a variable (found) and set it to True if something s found. You can then use that later on. An option would be to add one to a count every time a match is found then you could report how many matches there had been.


I hope this helps,</condition></condition></condition>
 
Last edited:
Upvote 0
Oh dear. :(

Note to self, I really must concentrate on the forum heading before posting!

I was doing quite well, I had not given an Excel answer to an Access question for some time.

Apologies,
 
Upvote 0

Forum statistics

Threads
1,221,771
Messages
6,161,847
Members
451,723
Latest member
Rachetsely

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