ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How to insert new worksheet based on # of rows in a data sourch (https://www.excelbanter.com/excel-discussion-misc-queries/445946-how-insert-new-worksheet-based-rows-data-sourch.html)

Rachel Rios

How to insert new worksheet based on # of rows in a data sourch
 
Hello,

I am trying to get the below VBA code to only copy "form" and create
new worksheet based on number of rows with data in my "data" sheet.
Is there a way that can be done?

Sub Copy_Sheets()

Dim i As Integer
Dim wks As Worksheet

For i = 1 To 45

Sheets("form").Copy After:=Sheets(2)
Next

End Sub

Don Guillett[_2_]

How to insert new worksheet based on # of rows in a data sourch
 
On Wednesday, May 2, 2012 10:09:21 AM UTC-5, Rachel Rios wrote:
Hello,

I am trying to get the below VBA code to only copy "form" and create
new worksheet based on number of rows with data in my "data" sheet.
Is there a way that can be done?

Sub Copy_Sheets()

Dim i As Integer
Dim wks As Worksheet

For i = 1 To 45

Sheets("form").Copy After:=Sheets(2)
Next

End Sub


more detail

Gord Dibben[_2_]

How to insert new worksheet based on # of rows in a data sourch
 
Assuming Column A has range of rows to count.

Sub Copy_Sheets()
Dim i As Integer
Dim rng1 As Integer
rng1 = Sheets("Data").Cells(Rows.Count, 1).End(xlUp).Row
MsgBox rng1 & " Sheets will be added"
For i = rng1 To 1 Step -1
Sheets("form").Copy after:=Sheets(2)
ActiveSheet.Name = "form" & i
Next
End Sub


Gord

On Wed, 2 May 2012 08:09:21 -0700 (PDT), Rachel Rios
wrote:

Hello,

I am trying to get the below VBA code to only copy "form" and create
new worksheet based on number of rows with data in my "data" sheet.
Is there a way that can be done?

Sub Copy_Sheets()

Dim i As Integer
Dim wks As Worksheet

For i = 1 To 45

Sheets("form").Copy After:=Sheets(2)
Next

End Sub



All times are GMT +1. The time now is 05:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com