2021-12-04

Copy specific row into newly created worksheets

I have successfully been able to take a range of cells and create worksheets from a template I have. I plan on using my template to do the work of copying and pasting the work items I have.

In my code, I need to also copy and paste the certain row into the new worksheets it already created.

Here is my code...

Sub CreateSheets()
 
Dim rng As Range
Dim cell As Range


On Error GoTo Errorhandling

Set rng = Application.InputBox(Prompt:="Select cell range:", _
Title:="Create sheets", _
Default:=Selection.Address, Type:=8)
 
For Each cell In rng

'Check if cell is not empty      
If cell <> "" Then
 
'Insert worksheet and name the worksheet based on cell value
Sheets("Template").Copy After:=Sheets("Unit Types")


'Name new sheet based off two cells on Bid Summary List Cells (Bi and Di)
ActiveSheet.Name = "UNIT-" & cell
    
'This is where I think I should add the copy/paste lines... but I don't know how.    
'Copy unit# row and paste in correct worksheet
    Range("XX:XX").Copy Range("XX:XX")
    
    End If

'Continue with next cell in cell range
Next cell
 
'Go here if an error occurs
Errorhandling:
 
'Stop macro
End Sub

In the pictures I showed where I would want to paste the information. This way I can link the cells to the appropriate areas in the template... and just run a vba to delete blank cells.

enter image description here enter image description here



from Recent Questions - Stack Overflow https://ift.tt/3Dq6j6C
https://ift.tt/eA8V8J

No comments:

Post a Comment