Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default How do I add a month to a filename extracted from a cell

Hi, I have a cell containing a date in the format ddmmyyy (South African
format) eg. 28/3/2006. I want to extract from this cell the value of the
month and year as "March 2006" and then use it to save the workbook name in a
folder as ("C:\Data\Import March 2006.xls"). Any ideas how to do this in code?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default How do I add a month to a filename extracted from a cell

If A1 is your cell, you can extract the information with:

format(month(A1),"MMMM") & " " & Year(A1)

To that, just concatenate the path prefix.

"Geoff" wrote:

Hi, I have a cell containing a date in the format ddmmyyy (South African
format) eg. 28/3/2006. I want to extract from this cell the value of the
month and year as "March 2006" and then use it to save the workbook name in a
folder as ("C:\Data\Import March 2006.xls"). Any ideas how to do this in code?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default How do I add a month to a filename extracted from a cell

Lets say your date is in A1

Sub SaveAsMonth()
datestamp = WorksheetFunction.Text([A1], "mmmmmm yyyy")
ActiveWorkbook.SaveAs "C:\Data\Import " & datestamp & ".xls"
End Sub

I like to put folder locations into a macro sheet on a workbook so that
you can do for example
ActiveWorkbook.SaveAs [A2] & datestamp & ".xls"
this allows you to change folder locations and work more transparently
and your code can work more generally

somethinglikeant

somethinglikeant

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How do I add a month to a filename extracted from a cell

Seems like it should be more direct, and it is:

Dim rng as Range
set rng = Thisworkbook.worksheets("Sheet1").Range("A1")
Thisworkbook.SaveAS "C:\Data\Import " & format(rng,"mmmm yyyy") & ".xls"

If rng contains a string rather than a date serial and you are having a
translation problem (day and month get transposed) then use

format(cdate(rng),"mmmm yyyy")
rather than
format(rng,"mmmm yyyy")


--
Regards,
Tom Ogilvy


"Geoff" wrote in message
...
Hi, I have a cell containing a date in the format ddmmyyy (South African
format) eg. 28/3/2006. I want to extract from this cell the value of the
month and year as "March 2006" and then use it to save the workbook name

in a
folder as ("C:\Data\Import March 2006.xls"). Any ideas how to do this in

code?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default How do I add a month to a filename extracted from a cell

Thanks guys for all your help - much appreciated - it works perfectly!

"Tom Ogilvy" wrote:

Seems like it should be more direct, and it is:

Dim rng as Range
set rng = Thisworkbook.worksheets("Sheet1").Range("A1")
Thisworkbook.SaveAS "C:\Data\Import " & format(rng,"mmmm yyyy") & ".xls"

If rng contains a string rather than a date serial and you are having a
translation problem (day and month get transposed) then use

format(cdate(rng),"mmmm yyyy")
rather than
format(rng,"mmmm yyyy")


--
Regards,
Tom Ogilvy


"Geoff" wrote in message
...
Hi, I have a cell containing a date in the format ddmmyyy (South African
format) eg. 28/3/2006. I want to extract from this cell the value of the
month and year as "March 2006" and then use it to save the workbook name

in a
folder as ("C:\Data\Import March 2006.xls"). Any ideas how to do this in

code?



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
Formula to sum values extracted from string Paul Martin[_2_] Excel Discussion (Misc queries) 10 February 3rd 10 11:20 PM
Cell("filename") doesn't update to new filename when do save as. Louis Excel Worksheet Functions 2 March 22nd 07 07:27 PM
how can the necessary information be extracted? Herbert Chan Excel Discussion (Misc queries) 11 January 16th 07 01:45 AM
Formula That Totals Extracted Values LDL Excel Worksheet Functions 2 October 26th 06 07:29 PM
transfer cell $ amount to other sheet month-to-month without overc Colin2u Excel Discussion (Misc queries) 1 July 28th 05 02:36 AM


All times are GMT +1. The time now is 10:37 AM.

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"