#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 16
Default Date Calculation

Hello,

I am trying to duplicate the following formula as a macro in vb:
B1=TEXT((MID(A1|1|4) & "/" & MID(A1|5|2) & "/" & MID(A1|7|2))-6|"YYYYMMDD")

I have following data in A:
20080101
20080102
....
20080131

I would like to then subtract 6 'days' from those values so that we have
this in B:
20071226
20071227
....
20080125

I've tried using the Format() function but it not displaying correctly.

Thank you
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 396
Default Date Calculation

With Range("A1")

Range("B1").Value = Format(DateSerial(Left(.Value, 4), Mid(.Value, 5,
2), Mid(.Value, 7, 2)) - 6, "YYYYMMDD")

End With



--
Wigi
http://www.wimgielis.be = Excel/VBA, soccer and music


"stevieb" wrote:

Hello,

I am trying to duplicate the following formula as a macro in vb:
B1=TEXT((MID(A1|1|4) & "/" & MID(A1|5|2) & "/" & MID(A1|7|2))-6|"YYYYMMDD")

I have following data in A:
20080101
20080102
...
20080131

I would like to then subtract 6 'days' from those values so that we have
this in B:
20071226
20071227
...
20080125

I've tried using the Format() function but it not displaying correctly.

Thank you

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Date Calculation

Try

=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))-6

Mike

"stevieb" wrote:

Hello,

I am trying to duplicate the following formula as a macro in vb:
B1=TEXT((MID(A1|1|4) & "/" & MID(A1|5|2) & "/" & MID(A1|7|2))-6|"YYYYMMDD")

I have following data in A:
20080101
20080102
...
20080131

I would like to then subtract 6 'days' from those values so that we have
this in B:
20071226
20071227
...
20080125

I've tried using the Format() function but it not displaying correctly.

Thank you

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 16
Default Date Calculation

Thank you Sir!

I was missing DateSerial function. I am googling it as we speak.


"Wigi" wrote:

With Range("A1")

Range("B1").Value = Format(DateSerial(Left(.Value, 4), Mid(.Value, 5,
2), Mid(.Value, 7, 2)) - 6, "YYYYMMDD")

End With



--
Wigi
http://www.wimgielis.be = Excel/VBA, soccer and music


"stevieb" wrote:

Hello,

I am trying to duplicate the following formula as a macro in vb:
B1=TEXT((MID(A1|1|4) & "/" & MID(A1|5|2) & "/" & MID(A1|7|2))-6|"YYYYMMDD")

I have following data in A:
20080101
20080102
...
20080131

I would like to then subtract 6 'days' from those values so that we have
this in B:
20071226
20071227
...
20080125

I've tried using the Format() function but it not displaying correctly.

Thank you

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
End Date Calculation (adding a start date duration) Silena K-K Excel Discussion (Misc queries) 5 January 25th 08 04:27 PM
date calculation praveen Excel Worksheet Functions 1 May 25th 07 08:00 AM
Tricky Date calculation: How to calculate a future date [email protected] Excel Discussion (Misc queries) 9 August 11th 06 04:24 AM
Date Calculation Alpur Excel Discussion (Misc queries) 0 November 15th 05 02:38 PM
Date Calculation Mukund Excel Worksheet Functions 3 January 11th 05 11:29 AM


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