code to automatically create new sheets

Drew

Board Regular
Joined
Feb 18, 2002
Messages
185
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

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Drew

Board Regular
Joined
Feb 18, 2002
Messages
185
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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
 

gplhl

Board Regular
Joined
Feb 23, 2002
Messages
150
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
 

Forum statistics

Threads
1,143,640
Messages
5,719,987
Members
422,256
Latest member
downeybm

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
Top