Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default programatically create new worksheet

to all you experts out there, I need some help with creating a macro.

I have 2 workbooks.
workbook 1 has one sheet with a template
workbook 2 has one sheet with about 200 rows

I would like to do 2 things here.
-automatically create new worksheets and have them named based on the
data in column C from workbook 2 while at the same time use the
template from workbook 1 to be included in the new named sheets.

I also have data in Columns D, E , and F in workbook 2 that I also
need created along with the new named sheets, and created in column A
rows 1, 2, and 3 respective to the newly named worksheets.

Any idea on how to go about doing this or am I not explaining this
clear enough?

Any help is greatly appreciated.

Thanks,

Chris
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default programatically create new worksheet

The code below copies the entire worksheet from the templet (not just
columns D:F) and places new worksheet in the workbook that contains the sheet
names. The macro is designed to be placed in the workbook with the sheet
names. The code will open the templet file at the start and then clos it at
the end. Change the Folder name and templet filename as necessary.


Sub newsheets()

Const Folder = "C:\temp\test\"
Const TempletName = "Book1.xls"

Workbooks.Open Filename:=Folder & TempletName
Set templetbk = ActiveWorkbook
Set templetsht = templetbk.ActiveSheet

With ThisWorkbook
Set sht1 = .ActiveSheet
RowCount = 1
Do While sht1.Range("A" & RowCount) < ""

templetsht.Copy _
after:=.Sheets(.Sheets.Count)
ActiveSheet.Name = sht1.Range("A" & RowCount)

RowCount = RowCount + 1
Loop
End With

templetbk.Close
End Sub

"Chris" wrote:

to all you experts out there, I need some help with creating a macro.

I have 2 workbooks.
workbook 1 has one sheet with a template
workbook 2 has one sheet with about 200 rows

I would like to do 2 things here.
-automatically create new worksheets and have them named based on the
data in column C from workbook 2 while at the same time use the
template from workbook 1 to be included in the new named sheets.

I also have data in Columns D, E , and F in workbook 2 that I also
need created along with the new named sheets, and created in column A
rows 1, 2, and 3 respective to the newly named worksheets.

Any idea on how to go about doing this or am I not explaining this
clear enough?

Any help is greatly appreciated.

Thanks,

Chris

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
Create VBA Function/Sub programatically within Excel VBA rael_lucid Excel Programming 2 September 28th 07 08:51 AM
How Do I Create an Excel 2007 Workbook Programatically Mark W. Robbins Excel Programming 0 June 3rd 06 08:39 AM
Adding VB code to worksheet programatically seegerp Excel Programming 2 March 29th 06 09:52 PM
Add code to a worksheet programatically Dave B[_9_] Excel Programming 2 December 9th 05 09:08 PM
Mapland Excel Addin - Programatically Create 1000 distinct maps Rich Cooper[_4_] Excel Programming 1 July 27th 04 06:07 AM


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