Macro to copy existing sheet and linking cells of new sheet to master sheet

Milo2019

New Member
Joined
Apr 27, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
This is the Macro I have to create a new sheet from my template (labeled as COQ 001) which works:
Sub CreateSheet()
Dim xName As String
Dim xSht As Object
Dim xNWS As Worksheet
On Error Resume Next
xName = InputBox("Please enter COQ Numeber. For Example: COQ 00X", "NEW QOQ")
If xName = "COQ 001" Then Exit Sub
Set xSht = Sheets(xName)
If Not xSht Is Nothing Then
MsgBox "Sheet cannot be created as there is already a worksheet with the same name in this workbook"
Exit Sub
End If
Sheets("COQ 001").Copy after:=Sheets(Sheets.Count)
Set xNWS = Sheets(Sheets.Count)
xNWS.Name = xName
End Sub

This is the macro I have to link the template sheet (COQ 001) to the master sheet which also works:
Sub Link2Log()
'
' Link2Log Macro
'

'
Rows("10:10").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("B10").Select
ActiveCell.FormulaR1C1 = "='COQ 002'!R[-3]C[5]"
Range("C10").Select
ActiveCell.FormulaR1C1 = "='COQ 002'!R[2]C:R[2]C[5]"
Range("D10").Select
ActiveCell.FormulaR1C1 = "='COQ 002'!R[-2]C[3]"
Range("E10").Select
ActiveCell.FormulaR1C1 = "='COQ 002'!R[-1]C[2]"
Range("G10").Select
ActiveCell.FormulaR1C1 = "='COQ 002'!R[40]C"
Range("G11").Select
End Sub

Question: How do I combine the two macros above into one, so that every time I create a new COQ sheet copied off the template, it will link the cells to the master sheet? I want it to add a row when I create a new sheet and each time link the cells to the master sheet. I don't know what to place in the above location to have it grab the newly created sheet and link it in leu of COQ 002 or the template sheet everytime , nor how to combine the two macros above. Please help, Thanks,
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I just need to combine these two macros into one button. I can attach the workbook if it would help.
Any help would be appreciated! Thanks!
 
Upvote 0
I just need to combine these two macros into one button. I can attach the workbook if it would help.
Any help would be appreciated! Thanks!
 
Upvote 0
I find your question a little confusing/unclear, though I am a very visual person.

I think it might be more helpful to me (and others) if you should us some sample of your data, and walked us through an example of what you are trying to do, step-by-step.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
Ok, maybe this will help:
This is a snapshot of the log. When I click on this button highlighted in yellow, It will generate a new change order based off of the template labeled as 'COQ 001' circled in red pen below.
1652740821498.png

from there I will click the 'link to log' button that is gray so that it will link specific cells from, the new COQ I created to this log I created.

The below highlighted in yellow are some of the cells that will link back to the log shown above.
1652740998665.png


Question 1
I need to make that into a single button instead of two. The macros are listed in the first post.

Question 2
As it is currently linked to COQ 001, How can I make each new COQ sheet that I make link to the log in the first snip it?

Any help would be great, Thanks,
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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