PC Review


Reply
Thread Tools Rate Thread

Date Format Frustrations

 
 
scrawny
Guest
Posts: n/a
 
      9th Apr 2007
G'Day,

Got a spreadsheet that imports data and unfortunately the date data
comes in the format of "dd.mm.yyyy". So I use a replace method to
change dots to slashes to get "dd/mm/yyyy". When I do this with the
replace in the edit menu it works fine. When I record the macro that
makes it all happen and place it in my VBA code it changes the date
format around to "m/dd/yyyy". So I tried recording the macro again
with the replace dialog box options and selecting the proper date
format... once again the menu option works fine but the actual code
doesn't (see below)...

Range("B469471").Select
Application.ReplaceFormat.NumberFormat = "d/mm/yyyy;@"
myRange.Replace What:=".", Replacement:="/", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False,
_
ReplaceFormat:=True

The Application.ReplaceFormat... line returns the following error:

Run-time error '-2147417848 (80010108)':
Method 'NumberFormat' of object 'CellFormat' failed

Anyone come across this before?

-Scrawny

 
Reply With Quote
 
 
 
 
scrawny
Guest
Posts: n/a
 
      9th Apr 2007
Oops...

Sorry if code is misleading - should be:

Set myRange = IMPORTED_DATA.Range("B469471")
Application.ReplaceFormat.NumberFormat = "d/mm/yyyy;@"
myRange.Replace What:=".", Replacement:="/", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False,_
ReplaceFormat:=True

 
Reply With Quote
 
Roger Govier
Guest
Posts: n/a
 
      9th Apr 2007
Hi

I can't answer why your code doesn't work, but try the following as an
alternative.

Sub convdate()
Dim i As Long
For i = 2 To 4 ' columns B to D
Range(Cells(469, i), Cells(471, i)).TextToColumns _
Destination:=Range(Cells(469, i), Cells(471, i)), _
DataType:=xlDelimited, FieldInfo:=Array(1, 4)
Next i
End Sub

It works fine for me converting dates like 9.4.7 to 09/04/2007.

My Regional Setting is UK and I use dd/mm/yyyy

--
Regards

Roger Govier


"scrawny" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> G'Day,
>
> Got a spreadsheet that imports data and unfortunately the date data
> comes in the format of "dd.mm.yyyy". So I use a replace method to
> change dots to slashes to get "dd/mm/yyyy". When I do this with the
> replace in the edit menu it works fine. When I record the macro that
> makes it all happen and place it in my VBA code it changes the date
> format around to "m/dd/yyyy". So I tried recording the macro again
> with the replace dialog box options and selecting the proper date
> format... once again the menu option works fine but the actual code
> doesn't (see below)...
>
> Range("B469471").Select
> Application.ReplaceFormat.NumberFormat = "d/mm/yyyy;@"
> myRange.Replace What:=".", Replacement:="/", LookAt:=xlPart, _
> SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False,
> _
> ReplaceFormat:=True
>
> The Application.ReplaceFormat... line returns the following error:
>
> Run-time error '-2147417848 (80010108)':
> Method 'NumberFormat' of object 'CellFormat' failed
>
> Anyone come across this before?
>
> -Scrawny
>



 
Reply With Quote
 
scrawny
Guest
Posts: n/a
 
      9th Apr 2007
You Legend!
Because the importer sheet (the sheet getting the data) only needs
Column B, C & D to have the format changed from something like
03.04.2007 - I just used the following code:
(Because the sheet is so huge and it's running on a network I'm trying
to stay away from using loops, ifs etc.)
(Also, The B469471 above is variable with the changeRange and
putRange addresses which is the actual code below...)

Set matchRange = IMPORTED_DATA.Range(changeRange.Offset(0,
1).Address & ":" & putRange.Offset(0, 1).Address)
matchRange.TextToColumns Destination:=matchRange,
DataType:=xlDelimited, FieldInfo:=Array(1, 4)
Set matchRange = matchRange.Offset(0, 1)
matchRange.TextToColumns Destination:=matchRange,
DataType:=xlDelimited, FieldInfo:=Array(1, 4)
Set matchRange = matchRange.Offset(0, 1)
matchRange.TextToColumns Destination:=matchRange,
DataType:=xlDelimited, FieldInfo:=Array(1, 4)

You know - this would never have happened if them bloomin Yanks didn't
have their standards imprinted into Microsoft Excel... (Despite what
regional settings you might have in place on your machine).

Oh well.

-Scrawny

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting complex date format to normal date format in Excel BlackNarcissus Microsoft Excel Misc 0 28th Jul 2011 04:28 PM
permanent conversion of 1904 date format to 1900 date format Jos Microsoft Excel Worksheet Functions 3 21st Jul 2009 06:32 PM
converting general date format data into short date format savigliano Microsoft Access Form Coding 3 27th Nov 2006 04:37 AM
Frustrations with RTF format. =?Utf-8?B?QVdlc25lcg==?= Microsoft VB .NET 4 7th Apr 2006 04:41 PM
code to convert date from TEXT format (03-02) to DATE format (200203) Gauthier Microsoft Excel Programming 0 22nd Sep 2004 03:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:15 PM.