PC Review


Reply
Thread Tools Rate Thread

Date reformat and export

 
 
joecrabtree
Guest
Posts: n/a
 
      3rd Dec 2007
To all,

I have a workbook that contains many worksheets named after a date for
example 2007911(1), 2007911(2) etc. (Format - yyyyddmm)

I want to be able to run a macro that will strip all the () (brakets)
out of the dates and insert an _, i.e. turn 2007911(1) into 2007911_1
and 2007911_2 etc.

I then want to be able to copy all the sheets in this format to a
workbook called PAT.xls. and then run or call a macro named 'test'
which is in a module in PAT.xls. I have a worksheet called control
which I do not wish to copy over to PAT.xls.

Is there an easy way to do this?

Thanks


Thanks in advance for your help,

Regards

Joseph Crabtree
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      3rd Dec 2007

Sub fixsheetname()

For Each sht In ActiveWorkbook.Sheets
If InStr(sht.Name, "(") > 0 Then
bracketpos = InStr(sht.Name, "(")
prefixname = Trim(Left(sht.Name, bracketpos - 1))
shtnumber = Trim(Mid(sht.Name, bracketpos + 1))
shtnumber = Trim(Left(shtnumber, InStr(shtnumber, ")") - 1))
sht.Name = prefixname & "_" & shtnumber
End If
Next sht
End Sub

"joecrabtree" wrote:

> To all,
>
> I have a workbook that contains many worksheets named after a date for
> example 2007911(1), 2007911(2) etc. (Format - yyyyddmm)
>
> I want to be able to run a macro that will strip all the () (brakets)
> out of the dates and insert an _, i.e. turn 2007911(1) into 2007911_1
> and 2007911_2 etc.
>
> I then want to be able to copy all the sheets in this format to a
> workbook called PAT.xls. and then run or call a macro named 'test'
> which is in a module in PAT.xls. I have a worksheet called control
> which I do not wish to copy over to PAT.xls.
>
> Is there an easy way to do this?
>
> Thanks
>
>
> Thanks in advance for your help,
>
> Regards
>
> Joseph Crabtree
>

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      3rd Dec 2007
I added to the code the COPY request. the code assumes the workbook PAT.XLS
is opend

Sub fixsheetname()

For Each sht In ActiveWorkbook.Sheets
If InStr(sht.Name, "(") > 0 Then
bracketpos = InStr(sht.Name, "(")
prefixname = Trim(Left(sht.Name, bracketpos - 1))
shtnumber = Trim(Mid(sht.Name, bracketpos + 1))
shtnumber = Trim(Left(shtnumber, InStr(shtnumber, ")") - 1))
sht.Name = prefixname & "_" & shtnumber

With Workbooks("Pat.xls")
sht.Copy after:=.Sheets(.Sheets.Count)
End With
End If
Next sht
End Sub

"Joel" wrote:

>
> Sub fixsheetname()
>
> For Each sht In ActiveWorkbook.Sheets
> If InStr(sht.Name, "(") > 0 Then
> bracketpos = InStr(sht.Name, "(")
> prefixname = Trim(Left(sht.Name, bracketpos - 1))
> shtnumber = Trim(Mid(sht.Name, bracketpos + 1))
> shtnumber = Trim(Left(shtnumber, InStr(shtnumber, ")") - 1))
> sht.Name = prefixname & "_" & shtnumber
> End If
> Next sht
> End Sub
>
> "joecrabtree" wrote:
>
> > To all,
> >
> > I have a workbook that contains many worksheets named after a date for
> > example 2007911(1), 2007911(2) etc. (Format - yyyyddmm)
> >
> > I want to be able to run a macro that will strip all the () (brakets)
> > out of the dates and insert an _, i.e. turn 2007911(1) into 2007911_1
> > and 2007911_2 etc.
> >
> > I then want to be able to copy all the sheets in this format to a
> > workbook called PAT.xls. and then run or call a macro named 'test'
> > which is in a module in PAT.xls. I have a worksheet called control
> > which I do not wish to copy over to PAT.xls.
> >
> > Is there an easy way to do this?
> >
> > Thanks
> >
> >
> > Thanks in advance for your help,
> >
> > Regards
> >
> > Joseph Crabtree
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reformat Date Field shairal Microsoft Access Queries 2 28th Jan 2009 06:00 PM
Reformat date to the first of the month FL610 Microsoft Access 6 3rd Jul 2008 01:41 AM
export access data to excel and reformat George Applegate Microsoft Access Getting Started 1 19th Apr 2008 01:50 AM
reformat cells for date Wackyracer Microsoft Excel Misc 9 3rd Apr 2008 12:42 AM
Reformat date 10106=Jan 1,06 =?Utf-8?B?TWFyaWE=?= Microsoft Access Queries 2 5th Jul 2006 10:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:26 PM.