Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default changing date format by macro in excel2000

i want to build a macro to change the format of the current workbook
from dd/mm/yyyy to dd/mm/yy
in excel2000
win XP

thank you
rozent
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default changing date format by macro in excel2000

Hi Rozent,

Try:
'=============
Sub ATest()
Dim rng As Range
Dim rCell As Range
Dim WB As Workbook
Dim SH As Worksheet

Set WB = ActiveWorkbook '<<======= CHANGE

For Each SH In WB.Worksheets
Set rng = SH.UsedRange
For Each rCell In rng.Cells
If rCell.NumberFormat Like "*/*/yyyy" Then
rCell.NumberFormat = "dd/mm/yy"
End If
Next rCell
Next SH

End Sub
'<<=============


---
Regards,
Norman



"?????" wrote in message
...
i want to build a macro to change the format of the current workbook
from dd/mm/yyyy to dd/mm/yy
in excel2000
win XP

thank you
rozent



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default changing date format by macro in excel2000

thank you norman, it helped.
is ther a shorter way?
can a macro change the definision in the control panel?

rozent

"Norman Jones" wrote:

Hi Rozent,

Try:
'=============
Sub ATest()
Dim rng As Range
Dim rCell As Range
Dim WB As Workbook
Dim SH As Worksheet

Set WB = ActiveWorkbook '<<======= CHANGE

For Each SH In WB.Worksheets
Set rng = SH.UsedRange
For Each rCell In rng.Cells
If rCell.NumberFormat Like "*/*/yyyy" Then
rCell.NumberFormat = "dd/mm/yy"
End If
Next rCell
Next SH

End Sub
'<<=============


---
Regards,
Norman



"?????" wrote in message
...
i want to build a macro to change the format of the current workbook
from dd/mm/yyyy to dd/mm/yy
in excel2000
win XP

thank you
rozent




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default changing date format by macro in excel2000

Hi Rozent,


can a macro change the definision in the control panel?


I am not aware of a means to effect a global change with a custom format.

is ther a shorter way?


If you refer to the length of the code, I really do not believe that this
should be a consideration.

If you refer to macro execution time,
you could wrap the code thus:

Application.ScreenUpdating = False
'code
application.ScreenUpdating = True.

If you were happy to limit processing to existing date values, as opposed to
custom formatted cells which might (or might not) contain values, then
increased efficiency might ensue by changing:

Set rng = SH.UsedRange


to:

Set rng = SH.UsedRange.SpecialCells _
(xlCellTypeConstants, xlNumbers)

For date values entered as constants.

If, with the preceding limitation to existing date values, such dates were
returned from formulae, then you could use a range assignment like:

Set rng = SH.UsedRange.SpecialCells _
(xlCellTypeFormulas, xlNumbers)

If the dates of interest potentially result from either constants or
formulae, you would need to loop through each of the SpecialCells ranges or
form a union. This would increase code length but might wll improve
execution time

As written, the suggested code changes the custom format irrespective of
whether the formatted cells are currently populated.

---
Regards,
Norman



"?????" wrote in message
...
thank you norman, it helped.
is ther a shorter way?
can a macro change the definision in the control panel?

rozent

"Norman Jones" wrote:

Hi Rozent,

Try:
'=============
Sub ATest()
Dim rng As Range
Dim rCell As Range
Dim WB As Workbook
Dim SH As Worksheet

Set WB = ActiveWorkbook '<<======= CHANGE

For Each SH In WB.Worksheets
Set rng = SH.UsedRange
For Each rCell In rng.Cells
If rCell.NumberFormat Like "*/*/yyyy" Then
rCell.NumberFormat = "dd/mm/yy"
End If
Next rCell
Next SH

End Sub
'<<=============


---
Regards,
Norman



"?????" wrote in message
...
i want to build a macro to change the format of the current workbook
from dd/mm/yyyy to dd/mm/yy
in excel2000
win XP

thank you
rozent






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default changing date format by macro in excel2000

hi norman
if i want to limit the macro only to the current worksheet
what is the macro

rozent

"Norman Jones" wrote:

Hi Rozent,


can a macro change the definision in the control panel?


I am not aware of a means to effect a global change with a custom format.

is ther a shorter way?


If you refer to the length of the code, I really do not believe that this
should be a consideration.

If you refer to macro execution time,
you could wrap the code thus:

Application.ScreenUpdating = False
'code
application.ScreenUpdating = True.

If you were happy to limit processing to existing date values, as opposed to
custom formatted cells which might (or might not) contain values, then
increased efficiency might ensue by changing:

Set rng = SH.UsedRange


to:

Set rng = SH.UsedRange.SpecialCells _
(xlCellTypeConstants, xlNumbers)

For date values entered as constants.

If, with the preceding limitation to existing date values, such dates were
returned from formulae, then you could use a range assignment like:

Set rng = SH.UsedRange.SpecialCells _
(xlCellTypeFormulas, xlNumbers)

If the dates of interest potentially result from either constants or
formulae, you would need to loop through each of the SpecialCells ranges or
form a union. This would increase code length but might wll improve
execution time

As written, the suggested code changes the custom format irrespective of
whether the formatted cells are currently populated.

---
Regards,
Norman



"?????" wrote in message
...
thank you norman, it helped.
is ther a shorter way?
can a macro change the definision in the control panel?

rozent

"Norman Jones" wrote:

Hi Rozent,

Try:
'=============
Sub ATest()
Dim rng As Range
Dim rCell As Range
Dim WB As Workbook
Dim SH As Worksheet

Set WB = ActiveWorkbook '<<======= CHANGE

For Each SH In WB.Worksheets
Set rng = SH.UsedRange
For Each rCell In rng.Cells
If rCell.NumberFormat Like "*/*/yyyy" Then
rCell.NumberFormat = "dd/mm/yy"
End If
Next rCell
Next SH

End Sub
'<<=============


---
Regards,
Norman



"?????" wrote in message
...
i want to build a macro to change the format of the current workbook
from dd/mm/yyyy to dd/mm/yy
in excel2000
win XP

thank you
rozent








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default changing date format by macro in excel2000

Hi Rozent,

hi norman
if i want to limit the macro only to the current worksheet
what is the macro


Try:
'============
Sub ATest1A()
Dim rng As Range
Dim rCell As Range
Dim SH As Worksheet

Set SH = ActiveSheet

Set rng = SH.UsedRange
For Each rCell In rng.Cells
If rCell.NumberFormat Like "*/*/yyyy" Then
rCell.NumberFormat = "dd/mm/yy"
End If
Next rCell

End Sub
'<<=============

---
Regards,
Norman


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
Changing the date format on the date table in a chart spudsnruf Charts and Charting in Excel 2 September 3rd 09 07:08 PM
mm:ss keeps changing to a date format DavARei Excel Discussion (Misc queries) 7 February 27th 09 01:31 PM
date format keeps changing Carrie Excel Discussion (Misc queries) 5 August 12th 08 10:31 PM
Macro to Change Changing Date Format Data to Text Rod Bowyer Excel Discussion (Misc queries) 3 October 11th 07 12:02 PM
Excel2000...use Ctrl-V, not Paste, in macro to Format Axis in a ch MacroPete Charts and Charting in Excel 6 March 24th 07 12:07 AM


All times are GMT +1. The time now is 11:53 PM.

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

About Us

"It's about Microsoft Excel"