Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Select cells by format with VBA

I'm trying to write a macro to convert 1904 dates to 1900
and vice versa (by adding or subtracting 1462 as
appropriate). That's quite simple but as I want the whole
worksheet processed at once I want the macro to examine
the format of each cell and make the change only where it
has a date format. Otherwise other data will be affected.
That's beyond my ability. Can anyone help me?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Select cells by format with VBA

Clive,

Try the macros below, which should change all the dates on the activesheet.

HTH,
Bernie
MS Excel MVP

Sub AddToDates()
Dim myCell As Range
For Each myCell In ActiveSheet.UsedRange. _
SpecialCells(xlCellTypeConstants)
If InStr(1, myCell.Value, "/") 0 Then
myCell.Value = myCell.Value + 1462
End If
Next
End Sub

Sub SubtractFromDates()
Dim myCell As Range
For Each myCell In ActiveSheet.UsedRange. _
SpecialCells(xlCellTypeConstants)
If InStr(1, myCell.Value, "/") 0 Then
myCell.Value = myCell.Value - 1462
End If
Next
End Sub


"Clive Smith" wrote in message
...
I'm trying to write a macro to convert 1904 dates to 1900
and vice versa (by adding or subtracting 1462 as
appropriate). That's quite simple but as I want the whole
worksheet processed at once I want the macro to examine
the format of each cell and make the change only where it
has a date format. Otherwise other data will be affected.
That's beyond my ability. Can anyone help me?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Select cells by format with VBA

What I should have added that it will change dates that are formatted with
/'s. You will need to modify the sub if your date format uses -'s.

Sorry about that,
Bernie
MS Excel MVP

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Clive,

Try the macros below, which should change all the dates on the

activesheet.

HTH,
Bernie
MS Excel MVP

Sub AddToDates()
Dim myCell As Range
For Each myCell In ActiveSheet.UsedRange. _
SpecialCells(xlCellTypeConstants)
If InStr(1, myCell.Value, "/") 0 Then
myCell.Value = myCell.Value + 1462
End If
Next
End Sub

Sub SubtractFromDates()
Dim myCell As Range
For Each myCell In ActiveSheet.UsedRange. _
SpecialCells(xlCellTypeConstants)
If InStr(1, myCell.Value, "/") 0 Then
myCell.Value = myCell.Value - 1462
End If
Next
End Sub


"Clive Smith" wrote in message
...
I'm trying to write a macro to convert 1904 dates to 1900
and vice versa (by adding or subtracting 1462 as
appropriate). That's quite simple but as I want the whole
worksheet processed at once I want the macro to examine
the format of each cell and make the change only where it
has a date format. Otherwise other data will be affected.
That's beyond my ability. Can anyone help me?





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Select cells by format with VBA

Many thanks
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Select cells by format with VBA

I think this should work (but pls correct me otherwise):

If IsDate(myCell) Then

Regards,
Sandy

Bernie Deitrick wrote:
What I should have added that it will change dates that are formatted with
/'s. You will need to modify the sub if your date format uses -'s.

Sorry about that,
Bernie
MS Excel MVP

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...

Clive,

Try the macros below, which should change all the dates on the


activesheet.

HTH,
Bernie
MS Excel MVP

Sub AddToDates()
Dim myCell As Range
For Each myCell In ActiveSheet.UsedRange. _
SpecialCells(xlCellTypeConstants)
If InStr(1, myCell.Value, "/") 0 Then
myCell.Value = myCell.Value + 1462
End If
Next
End Sub

Sub SubtractFromDates()
Dim myCell As Range
For Each myCell In ActiveSheet.UsedRange. _
SpecialCells(xlCellTypeConstants)
If InStr(1, myCell.Value, "/") 0 Then
myCell.Value = myCell.Value - 1462
End If
Next
End Sub


"Clive Smith" wrote in message
...

I'm trying to write a macro to convert 1904 dates to 1900
and vice versa (by adding or subtracting 1462 as
appropriate). That's quite simple but as I want the whole
worksheet processed at once I want the macro to examine
the format of each cell and make the change only where it
has a date format. Otherwise other data will be affected.
That's beyond my ability. Can anyone help me?





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
Locked Several Worksheets, allow format cells/select unlocked cell Ana24 Excel Discussion (Misc queries) 2 September 26th 09 01:15 AM
Up down arrow keys do not select cells if select locked cells unch roandrob Excel Discussion (Misc queries) 3 May 18th 09 12:48 AM
how do you "select locked cells" w/o "select unlocked cells"? princejohnpaulfin Excel Discussion (Misc queries) 3 July 16th 05 03:53 AM
Select format cells Custom but Saves As Specil Why. Steved Excel Worksheet Functions 0 March 13th 05 12:06 AM
When I select "format cells", the format dialog box does not disp. Andy S. Excel Worksheet Functions 2 November 23rd 04 03:49 AM


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