Macro to check if Sheet exists and if not, create it using a template

xavisaus

New Member
Joined
Dec 1, 2021
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hello

I am trying to make a macro that, when pressing a hyperlink to another sheet on the same book, checks if the hyperlink is valid (ergo the sheet exists), and if it does not exist, copy a defined Template with the name given on a cell. This would have to work for a whole table.

1638344267689.png


The image shows the table I created, where the column P is column A, starting on 11 and colun P/N is column B, starting on 11. The idea is that if I click on the hyperlink on P/N GENERAL, the macro automatically checks if the sheet is created and if not, create it copying it from a template, and renaming using the value contained on the cell on the left side.

Example, I click on the hyperlink CM000000-000. If it is created, the hyperlink will take me to that sheet. If not, the macro will copy a "Template" and rename it to 100000_0 (value on the left of the hyperlink).
Same with all positions on the column P/N GENERAL

Additionally, if the value on the column P/N GENERAL contains a "-", a different template should be used for the copy. Let's say "Template2"

Thanks!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
So, where is "template"? Is it a worksheet? or a range in specific sheet?
 
Upvote 0
Hello, Template will be a worksheet placed on the same Book
 
Upvote 0
hi xavisaus,
Welcome to the board.

I would suggest providing a sample file containing your initial template and desensitized master data. This would enable everyone trying to help, to better understand the query and suggest solutions accordingly, rather then interpreting the query and making assumptions.

In the meantime, go through below post and see if you find it helpful.

hth....
 
Upvote 0
hi xavisaus,
Welcome to the board.

I would suggest providing a sample file containing your initial template and desensitized master data. This would enable everyone trying to help, to better understand the query and suggest solutions accordingly, rather then interpreting the query and making assumptions.

In the meantime, go through below post and see if you find it helpful.

hth....He
Hello @fadee2

I am not able to attach an excel file here. I am new to the forum so I need to learn how to do it. Is there a special way to do it?
 
Upvote 0
Go through forum rules to get familiar with rules and regulations of the board.

You can use any free file sharing service like google drive or dropbox or onedrive, to upload your file and share the link in the thread.
 
Upvote 0
Hello @fadee2

Here is the link to the sample.
WORKBOOK.xlsx

I created two template sheets:
  • "Template xx" to use when creating sheets with only 2 digits
  • "Template xxx" to use when creating sheets with more than 2 digits without "-" or "_"
  • "Template -" to use when creating sheets with "-" on GENERAL P/N column or "_" on S column is work in progress...
The workbook have already a macro to order all the sheets alphabetically

Many thanks
 
Upvote 0
I m sorry, but I can not make anything from the workbook you provided, as each worksheet shows only errors, which I suppose is because of the formulae placed within. I'd suggest creating a workbook, with values only (paste special as values) and reuploading the workbook.

hth...
 
Upvote 0
Hello @fadee2
The errors only occur on the templates, since the name of the sheet is not properly set. When you put a correct name, everything is filled out automatically, see sheet 10 or 10000 or whatever appart from the template
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,802
Members
449,095
Latest member
m_smith_solihull

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