Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default changing a string date into a 'date'

I usually work on Access databases but i was given an excel worksheet that
was exported from Sage accounting software so that the acountants could work
with it. HOwever it seems to be exporting dates in a string format that we
just cant change into a date.

so i tried to make a sub that can be called from a macro which takes a range
of cells and reformats them into dates.

Dim oldDate As String
Dim NewDate As Date
Dim day As Integer
Dim month As Integer
Dim year As Integer

For Each c In Range(ActiveWindow.RangeSelection.Address)
oldDate = c.Value
day = Left(oldDate, 2)
month = Mid(oldDate, 4, 2)
year = Right(oldDate, 4)
NewDate = day + "/" + month + "/" + year
Next c

End Sub

However im getting the following error:
Type Mismatch and its highlighting that last line 'Newdate = ....'
when i look at the variables i can see that htey are holding the values i
want but i cant rebuild it into a date, any help on this??

with much thanks
Amit


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 105
Default changing a string date into a 'date'

DowningDevelopments wrote:
I usually work on Access databases but i was given an excel worksheet that
was exported from Sage accounting software so that the acountants could work
with it. HOwever it seems to be exporting dates in a string format that we
just cant change into a date.

so i tried to make a sub that can be called from a macro which takes a range
of cells and reformats them into dates.

Dim oldDate As String
Dim NewDate As Date
Dim day As Integer
Dim month As Integer
Dim year As Integer

For Each c In Range(ActiveWindow.RangeSelection.Address)
oldDate = c.Value
day = Left(oldDate, 2)
month = Mid(oldDate, 4, 2)
year = Right(oldDate, 4)
NewDate = day + "/" + month + "/" + year
Next c

End Sub

However im getting the following error:
Type Mismatch and its highlighting that last line 'Newdate = ....'
when i look at the variables i can see that htey are holding the values i
want but i cant rebuild it into a date, any help on this??

with much thanks
Amit

-----------------------------

You're trying to force text into a variable you've defined as a date type.
Instead try:

NewDate = DateSerial(year, month, day)

Bill
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default changing a string date into a 'date'

Try:

NewDate=Datevalue(OldDate)


"DowningDevelopments" wrote:

I usually work on Access databases but i was given an excel worksheet that
was exported from Sage accounting software so that the acountants could work
with it. HOwever it seems to be exporting dates in a string format that we
just cant change into a date.

so i tried to make a sub that can be called from a macro which takes a range
of cells and reformats them into dates.

Dim oldDate As String
Dim NewDate As Date
Dim day As Integer
Dim month As Integer
Dim year As Integer

For Each c In Range(ActiveWindow.RangeSelection.Address)
oldDate = c.Value
day = Left(oldDate, 2)
month = Mid(oldDate, 4, 2)
year = Right(oldDate, 4)
NewDate = day + "/" + month + "/" + year
Next c

End Sub

However im getting the following error:
Type Mismatch and its highlighting that last line 'Newdate = ....'
when i look at the variables i can see that htey are holding the values i
want but i cant rebuild it into a date, any help on this??

with much thanks
Amit


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default changing a string date into a 'date'

Hi Amit,

You have omitted to indicate the string date format that you want to
convert.

---
Regards,
Norman



"DowningDevelopments" wrote
in message ...
I usually work on Access databases but i was given an excel worksheet that
was exported from Sage accounting software so that the acountants could
work
with it. HOwever it seems to be exporting dates in a string format that we
just cant change into a date.

so i tried to make a sub that can be called from a macro which takes a
range
of cells and reformats them into dates.

Dim oldDate As String
Dim NewDate As Date
Dim day As Integer
Dim month As Integer
Dim year As Integer

For Each c In Range(ActiveWindow.RangeSelection.Address)
oldDate = c.Value
day = Left(oldDate, 2)
month = Mid(oldDate, 4, 2)
year = Right(oldDate, 4)
NewDate = day + "/" + month + "/" + year
Next c

End Sub

However im getting the following error:
Type Mismatch and its highlighting that last line 'Newdate = ....'
when i look at the variables i can see that htey are holding the values i
want but i cant rebuild it into a date, any help on this??

with much thanks
Amit




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default changing a string date into a 'date'

excellent,
that was really helpful, i knew there had to be a function somewhere but i
just couldnt find it all afternoon!

with much thanks.

Amit

"Bill Martin" wrote:

DowningDevelopments wrote:
I usually work on Access databases but i was given an excel worksheet that
was exported from Sage accounting software so that the acountants could work
with it. HOwever it seems to be exporting dates in a string format that we
just cant change into a date.

so i tried to make a sub that can be called from a macro which takes a range
of cells and reformats them into dates.

Dim oldDate As String
Dim NewDate As Date
Dim day As Integer
Dim month As Integer
Dim year As Integer

For Each c In Range(ActiveWindow.RangeSelection.Address)
oldDate = c.Value
day = Left(oldDate, 2)
month = Mid(oldDate, 4, 2)
year = Right(oldDate, 4)
NewDate = day + "/" + month + "/" + year
Next c

End Sub

However im getting the following error:
Type Mismatch and its highlighting that last line 'Newdate = ....'
when i look at the variables i can see that htey are holding the values i
want but i cant rebuild it into a date, any help on this??

with much thanks
Amit

-----------------------------

You're trying to force text into a variable you've defined as a date type.
Instead try:

NewDate = DateSerial(year, month, day)

Bill

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Date string to date format Joe M. Excel Discussion (Misc queries) 7 May 6th 10 02:46 PM
Changing the date format on the date table in a chart spudsnruf Charts and Charting in Excel 2 September 3rd 09 07:08 PM
Cell contents changing to date and not date George Applegate Excel Worksheet Functions 3 October 17th 06 10:53 PM
When I open my past invoice it keeps changing date to todays date Stop date changing to todays in Excel Excel Worksheet Functions 2 October 7th 05 04:54 PM
Converting a string date into a Excel Date Phillips Excel Programming 0 November 24th 03 08:54 PM


All times are GMT +1. The time now is 06:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"