Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

function using if and

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Function using IF AND

Function using IF AND

ResolvedVersion 2003

David has attended:
Excel VBA Intro Intermediate course

Function using IF AND

Hello Simon,

I attended training 17/18 June, I asked your about creating a function using IF AND statements or an alternative to workout if dates fall within a month and you said to submit the question to the forum so here it is.

I have a spreadsheet for payments and in each month someone can be on Full Pay or Half Pay.
So if Half pay started on 15th June the function would look to see if 15th June was between 1 amd 30th


I need to create a function that can work this out as using functions in the front of excel I am limited to 7 If statements.

Thank You

RE: Function using IF AND

Hi David

Thanks for your question

This is difficult to answer precisely without seeing the spreadsheet. However the key is probably the datepart function which can be used to check the day element of a date.

So



Dim dteDate As Date

dteDate = #2/10/2010#

If DatePart("d", dteDate) > 1 Then

If DatePart("d", dteDate) < 9 Then

MsgBox "do Stuff"
Exit Sub

End If

End If

MsgBox "don't do stuff"



The above checks to see if the day element of a date is between 1 and 9. If so it does one thing, otherwise it does something else.

Hope this helps

Regards

Stephen

RE: Function using IF AND

Hi Stephen

Thanks for coming back to me, although slightly confused with this.

Not sure why checking the day element of a date will help.

Regards

David

RE: Function using IF AND

Hi david

Sorry, perhaps I have misunderstood your needs.
I thought that you wanted to check whether a date fell between 2 dates in a particular month. So you might want to see if the 15th of june fell between say the first and the 19th of that month.
If this is not the case could you please clarify?

Thanks

Stephen

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Adding up time greater than 24 hours

When you add up time if it exceeds 24 hours i.e 27 hours appears as 03:00. Go to Format / Cells / Number / Custom. The format is hh:mm but if change it to [hh]:mm it will add up to the correct amount of hours.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.