Can't think my way thru the logic

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,486
I have some dates and integers Row 3) across several columns -- The below code in "Worksheet_Change" code. If my target value is say 20
I need for the Msgbox to appear with the statement "You have entered a Weekend Date". What am I not doing right? The Range Name "VALIDDAYS" is a joined range G3:K3, M3:Q3 and the For Each is properly reading each one correctly

Excel 2012
GHIJKLMN
115-Sep16-Sep17-Sep18-Sep19-SepX22-Sep23-Sep
2MonTueWedThuFriMonTue
315161718192223

<COLGROUP><COL style="BACKGROUND-COLOR: #dae7f5"><COL><COL><COL><COL><COL><COL><COL><COL></COLGROUP><THEAD>
</THEAD><TBODY>
</TBODY>
Cash Proj



Code:
.....
For Each C In Range("ValidDays").Cells
If C.Value <> Target.Value Then
'Do nothing
Else
MsgBox "You have entered a Weekend Date"
Application.Undo
Exit For
End If
Next C
[/code}
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Isn't all of the date entry done in row 1? Rows 2 and 3 are just the same date formatted differently.
 
Upvote 0
Where is the target value of 20 coming from? Is this when you type a date in the first row?
If so, wouldn't you need to extract the day from the date you entered to get 20?
 
Upvote 0
Thanks for looking Shg,,

This is a monthly budget spread across umpteen columns

In my Column D (not shown) I enter on any row between (5 and 70) a number for the day of the month I wish to pay a given amt (in Cell E33); So like for example in Cell D33 - the enter the number 20; I want my macro to search my row 3 range and if it doesn't find my target (20), it delivers the message "THE 20th is a Weekend Date - Try Again!!").

I'm brain dead on this one...

Thanks,

Jim
 
Upvote 0
Why not just use data validation? =WEEKDAY(entrycell, 2) <=5
 
Upvote 0
Ok Guys, I tried this.. (it seems to work) Comments????

Code:
With Range("ValidDays").Cells
    Set R = .Find(Target.Value)
    
End With
If R Is Nothing Then
        MsgBox "You have entered a Weekend Date"
        Application.Undo
End If
 
Upvote 0
It seems like overkill to use VBA for this.
 
Upvote 0
I ended up doing this, and it seems to work FINE..
Code:
CurrYr = Year(Range("G1"))
CurrMo = Month(Range("G1"))
CurrDy = Day(Range("G1"))
If CurrDy < Target.Value Then
Paydate = DateSerial(CurrYr, CurrMo, Target)
Else
Paydate = DateSerial(CurrYr, CurrMo + 1, Target)
End If

If Weekday(Paydate, 2) = 6 Or Weekday(Paydate, 2) = 7 Then
        MsgBox "You have entered a Weekend Date"
        Application.Undo

Thanks for your input. Jim
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

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