Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi All,
Formatting issue with a macro. Report with dates formatted as dd.mm.yyyy is changed by Columns("G:G").Select Selection.Replace What:=".", Replacement:="/", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False Selection.NumberFormat = "dd/mm/yyyy;@" Columns("A:N").Select Selection.Sort Key1:=Range("G2"), Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal Range("B1").Select BUT, on some cells, the format of the date = mm/dd/yyyy. Subsequently my sort is incorrect. Seriously going bald over this one. Any help much appreciated. Cheers John |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If you have 01.02.2003 in a cell, then do your mass change, you'll be left with
01/02/2003. Excel will see it as a date -- and if your windows short date format is in mdy order, that cell will become Jan 2, 2003. If you have 31.01.2003, you'll end up with 31/01/2003 and excel won't even know that it's a date -- since it doesn't match the windows short date (mdy order). Instead of using edit|replace, try recording a macro when you select your range. data|text to columns fixed width, no lines and no new lines and choose dmy (to match the data--not to match what you want) Then apply the formatting you like (dd/mm/yyyy) And sort your data. And stop the recorder. John wrote: Hi All, Formatting issue with a macro. Report with dates formatted as dd.mm.yyyy is changed by Columns("G:G").Select Selection.Replace What:=".", Replacement:="/", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False Selection.NumberFormat = "dd/mm/yyyy;@" Columns("A:N").Select Selection.Sort Key1:=Range("G2"), Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal Range("B1").Select BUT, on some cells, the format of the date = mm/dd/yyyy. Subsequently my sort is incorrect. Seriously going bald over this one. Any help much appreciated. Cheers John -- Dave Peterson |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Spot on Dave,
Many thanks "Dave Peterson" wrote: If you have 01.02.2003 in a cell, then do your mass change, you'll be left with 01/02/2003. Excel will see it as a date -- and if your windows short date format is in mdy order, that cell will become Jan 2, 2003. If you have 31.01.2003, you'll end up with 31/01/2003 and excel won't even know that it's a date -- since it doesn't match the windows short date (mdy order). Instead of using edit|replace, try recording a macro when you select your range. data|text to columns fixed width, no lines and no new lines and choose dmy (to match the data--not to match what you want) Then apply the formatting you like (dd/mm/yyyy) And sort your data. And stop the recorder. John wrote: Hi All, Formatting issue with a macro. Report with dates formatted as dd.mm.yyyy is changed by Columns("G:G").Select Selection.Replace What:=".", Replacement:="/", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False Selection.NumberFormat = "dd/mm/yyyy;@" Columns("A:N").Select Selection.Sort Key1:=Range("G2"), Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal Range("B1").Select BUT, on some cells, the format of the date = mm/dd/yyyy. Subsequently my sort is incorrect. Seriously going bald over this one. Any help much appreciated. Cheers John -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Issue with dates being pasted correctly | Excel Discussion (Misc queries) | |||
When subtracting dates issue | Excel Discussion (Misc queries) | |||
subtracting two dates issue | Excel Discussion (Misc queries) | |||
Issue with copy/paste dates from filtered data | Excel Discussion (Misc queries) | |||
Macro for formatting columns with dates, weekdays, and widths? | Excel Programming |