code to automatically create new sheets

Drew

Board Regular
Joined
Feb 18, 2002
Messages
187
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi all,
I have a VBA related question (I’m helping out a co-worker but I have no VBA experience).
The following code essentially looks at a list of companies from the “reports” sheet; puts the first name from that list in cell c15 on sheet “bpnoi”; performs an essbase extract on sheet “bpnoi” (Del range); prints results from “bpnoi”; loops through company list from the “reports” sheet.
What I would like to do is replace the printing code with code that will add new sheets. I know this is possible from what I found in prior posts, but I couldn't piece together the code.
Thanks for the help.
Drew

Sub printreport()
Sheets("bpnoi").Select
ColIndex = 3
UnitIndex = 3
Rows("11:600").Select
'Selection.RowHeight = 12.75

While Not IsEmpty(Worksheets("Reports").Cells(UnitIndex, "A"))

range("del").Select
Dim Del As range
Set Del = ThisWorkbook.Worksheets("bpnoi").range("Del")


If (Worksheets("Reports").Cells(UnitIndex, ColIndex) = 1) Then
ActiveSheet.Cells(15, "C") = "'" & Worksheets("Reports").Cells(UnitIndex, "A")
W = EssVRetrieve("bpnoi", Del, 1)
ActiveWindow.SelectedSheets.PrintOut Copies:=1
End If
UnitIndex = UnitIndex + 1

Wend


End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Gary,
I placed the code in but a run-time error occurred. Of course while looking over my request I found out that I may not have explained properly...
After the program executes the essbase retrieval, I want to copy the "bpnoi" sheet to a new sheet with a name from cell C15 (or the UnitIndex).
Thanks,
Drew
 
Upvote 0
On 2002-10-22 14:11, Drew wrote:
Gary,
I placed the code in but a run-time error occurred. Of course while looking over my request I found out that I may not have explained properly...
After the program executes the essbase retrieval, I want to copy the "bpnoi" sheet to a new sheet with a name from cell C15 (or the UnitIndex).
Thanks,
Drew

NewSheetName = Range("C15").Value
Sheets("bpnoi").Copy After:=ActiveSheet
ActiveSheet.Name = NewSheetName
 
Upvote 0

Forum statistics

Threads
1,215,540
Messages
6,125,409
Members
449,223
Latest member
Narrian

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top