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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,223,637
Messages
6,173,488
Members
452,515
Latest member
archcalx

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