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

microsoft access vba courses - recognising dates

Forum home » Delegate support and help forum » Microsoft VBA Training and help » microsoft access vba courses - Recognising Dates

microsoft access vba courses - Recognising Dates

ResolvedVersion Standard

James has attended:
Excel VBA Intro Intermediate course

Recognising Dates

Hi Carlos,

I am currently writing a macro that, in one section of it, needs to search through a list of dates (row by row assigning each date to a variable and comparing using SelectCase). Unfortunately the list is an export from a piece of software that creates date cells in the format
" 12/31/2007"

The problem occurs when the cell shows
" 01/02/2008" to " 01/12/2008"
excel seems to treat this as dd/mm/yyyy and then back to mm/dd/yyyy when the middle value is more than 12.

I then use the line:
DateValue = ActiveCell.Value
to assign the data in this cell to the variable "DateValue".

Is there anything I can add to this line to assign the variable in a uniform manner?

Regardss,

James

RE: Recognising Dates

I have just found one solution for this - changing my computers regional setting to US!
Is this the only fix or is there an easier one?

RE: Recognising Dates

Hi James

Received the e-mail but there was just an image of the regional options dialog box attached.

Could you send the workbook?

I'm busy training the next few days but as soon as I get some time I'll look at it.

Carlos

RE: Recognising Dates

James

First Don't use DateValue as a variable name. This is a Date Function in Excel

I created 2 variables :

1. MyDate - This holds the date being compared to
2. ImportDate - This will hold each of the imported dates to compare

Now compare the two dates eg:

MyRow = 1

ImportDate = Cells(MyRow,1).Value

If MyDate = ImportDate then

<Do code>

MyRow = MyRow + 1

End If

This can loop through all the dates

By doing this the computer saves the imported date as UK.

Hope this helps. If not please send me the Weorkbook with your code and I'll see what I can do

Regards

Carlos

RE: Recognising Dates

Carlos,

I have a similar code setup for the loop (just with a couple more variables - firstdate, seconddate etc) with a select case instead of an IF.

I have tried changing DateValue to ImportDate but this doesn't work.
Can you send me your email address so that I can attach the workbook? I can't seem to attach files to this reply...

Regards,

James

RE: Recognising Dates

Hi James

Send the workbook to

info at stl-training.co.uk

Attention Carlos

and my collegues will forward it to me

Regards

Carlos

 

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.

VBA tip:

Good coding practice

It is important that you always comment the VBA code that you write. By doing this it will make the code much easier to read, as both yourself and other people will be able to see what the code is doing or meant to be doing. This is very important if there is more than one person who writes code in the company as you may have different styles of coding and may not really understand what the other person is trying to do. Also if you write some code and then do not touch it for a year or so you may actually forget what it is meant to be doing. so it is very important to include comments throughout your code and try and make sure that they are as useful as possible

View all VBA hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.