Date Formats

Jameo

Active Member
Joined
Apr 14, 2011
Messages
270
Hi all,

I have dates in the following form:

29/05/2011 07:00:00

I also have a macro to automatically fill a sheet with dates from a selected start date and end date:

Code:
Public Sub Dates2()
Dim StDate As Date
Dim EnDate As Date
Dim IntRow As Integer
Dim CuDate As Date
Dim LRow As Long
 
LRow = Sheets("BoundGraph").Range("A" & Rows.Count).End(xlUp).Row
StDate = Sheets("ControlPage").Cells(25, 10).Value
EnDate = Sheets("ControlPage").Cells(26, 10).Value
CuDate = StDate - 1
IntRow = 2
Sheets("BoundGraph").Select
Cells.Clear
Do
CuDate = CuDate + 1
IntRow = IntRow + 1
Sheets("BoundGraph").Range("A" & IntRow).Value = CuDate
Loop Until CuDate = EnDate
 
End Sub

I then have a vlookup that looks up the relevent data in the "BoundGraph" sheet.

However I keep getting an NA error as the date formats are different.

I have tried changing the date format in the sheet that is being looked up, but even though it doesn't display the 07:00 bit, it is still in the cell value.

Does anyone have any solutions to this issue?

Thanks in advance
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
What VLOOKUP form are you using? Presumably you should be using the one with 4th argument set to TRUE (or omitted altogether) so that an exact match isn't required (your dates in the lookup sheet are all ascending so you can use this form).
 
Upvote 0
I thought this myself Richard, and initially I had the forth argument set to a specific range, however, I have since changed that to TRUE (and left it blank), but it is still not functioning. There is no issue with the actual formula as upon changing the date and removing the 07:00 it functions correctly.

Unfortunately the data is imported in the dd/mm/yyyy hh:mm format.

An example of my formula is:
=VLOOKUP(A4,CompiledAgreed!A4:AA35,2,TRUE)
 
Upvote 0
I've made a really ugly fix to this issue by adding a time value to my date populating macro:

Code:
Public Sub Dates2()
Dim StDate As Date
Dim EnDate As Date
Dim IntRow As Integer
Dim CuDate As Date
Dim LRow As Long
Dim TValue as Date
 
LRow = Sheets("BoundGraph").Range("A" & Rows.Count).End(xlUp).Row
StDate = Sheets("ControlPage").Cells(25, 10).Value
EnDate = Sheets("ControlPage").Cells(26, 10).Value
CuDate = StDate - 1
IntRow = 2
Sheets("BoundGraph").Select
Cells.Clear
 
TValue = TimeValue("07:00:00")
 
CuDate = CuDate + TValue
EnDate = EnDate + TValue

Do
CuDate = CuDate + 1
IntRow = IntRow + 1
Sheets("BoundGraph").Range("A" & IntRow).Value = CuDate
Loop Until CuDate = EnDate
 
End Sub

But if anyone has a more elegent method of fixing this issue, please let me know.

Thanks
 
Upvote 0
Does anyone have any further input on this matter?

Thanks


try using the =left() function to extract the date part of your data into a seperate column and perform the vlookup on this data? you can probably build this into the vlookup although I'm not sure of the syntax
 
Upvote 0
Do you get #N/A returns with all dates or just some of them? You should only get a #N/A if the date you are looking up is earlier than the earliest date in the lookup range, otherwise there will alswys be a date within the lookup range less than than the lookup value so some value should be returned.
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,266
Members
452,902
Latest member
Knuddeluff

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