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

R

Rachel Rios

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
 
D

Don Guillett

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
 
G

Gord Dibben

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top