Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Date Format Frustrations

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("B469:D471").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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Date Format Frustrations

Oops...

Sorry if code is misleading - should be:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,886
Default Date Format Frustrations

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" wrote in message
ups.com...
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("B469:D471").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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Date Format Frustrations

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 B469:D471 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
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
IRR Calculation Frustrations jkramos2005 Excel Discussion (Misc queries) 2 December 3rd 08 09:01 PM
Concatenation frustrations.... Steve P[_2_] Excel Worksheet Functions 8 November 17th 08 09:54 PM
irr, xirr, npv frustrations Zachary Chan Excel Worksheet Functions 4 October 25th 05 04:41 AM
DSUM frustrations Paul Adams Excel Worksheet Functions 3 November 12th 04 10:59 AM
DSUM frustrations Paul Adams Excel Worksheet Functions 0 November 12th 04 10:56 AM


All times are GMT +1. The time now is 08:01 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"