copy rows to each new sheet

sean1541

New Member
Joined
Feb 14, 2023
Messages
31
Office Version
  1. 2016
Platform
  1. MacOS
Hi i want to be able to copy data from rows on Master sheet to new sheets
this is what i have so far it will put row data only for first row i want it to move down all rows that have data in
Colum C Master sheet ahd copy to all new sheets.
Thanks for any Help.
Sean

Sub Create()
Dim rng As Range, rngLoop As Range, ws As Worksheet

If Not SheetExists("Template") Then
MsgBox "The Template sheet does not exist. Make sure the Template is included before processing.", vbCritical + vbOKOnly
Exit Sub
End If

Application.ScreenUpdating = False

With ActiveWorkbook.Sheets("Master")
Set rng = .Range("c2", "c" & .Cells(Rows.Count, "c").End(xlUp).Row).SpecialCells(xlCellTypeConstants, xlTextValues)

For Each rngLoop In rng
If Not SheetExists(rngLoop.Value) Then
ActiveWorkbook.Sheets("Template").Copy After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)
Set ws = ActiveSheet
ws.Name = rngLoop.Value
Else
Set ws = ActiveWorkbook.Sheets(rngLoop.Value)
End If
ws.Range("A2").Resize(, 11).Value = .Range("A2:K2").Value
ws.Range("A130").Resize(, 11).Value = .Range(.Cells(rngLoop.Row, 1), .Cells(rngLoop.Row, 11)).Value


Next
.Activate
End With

Application.ScreenUpdating = True
End Sub



Function SheetExists(shtName As String, Optional wb As Workbook) As Boolean
Dim sht As Worksheet

If wb Is Nothing Then Set wb = ThisWorkbook
On Error Resume Next
Set sht = wb.Sheets(shtName)
On Error GoTo 0
SheetExists = Not sht Is Nothing
End Function
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Maybe, but not sure I correctly understood your request.
VBA Code:
Change:
ws.Range("A2").Resize(, 11).Value = .Range("A2:K2").Value

To:
ws.Range("A2").Resize(, 11).Value = .Range("A" & rngLoop.Row & ":K" & rngLoop.Row).Value
 
Upvote 1
Solution
ws.Range("A2").Resize(, 11).Value = .Range("A" & rngLoop.Row & ":K" & rngLoop.Row).Value
Thanks a million i have been trying to fix this for long time
I realy appreciate your help works perfect.
Thank you
Regards,
Sean.
 
Upvote 0
Thanks for the positive feedback(y), glad having been of some help.
 
Upvote 0

Forum statistics

Threads
1,224,802
Messages
6,181,048
Members
453,014
Latest member
Chris258

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