Generate sheet from a template when a cell is filled in "Master"

MrNSC

New Member
Joined
Aug 22, 2017
Messages
2
Hello everyone.
I've been reading the forum for a few days before asking any help. I'm a total VBA n00b.
it would be great if someone could help me.
I've used some code from several posts to meet my needs, but I now need an integrated approach.

Here's what I need to do:

  • I have a master sheet with suppliers name on B column
  • I have a template sheet which is replicated whenever I add a new supplier on the master sheet and the new sheet is created with that supplier's name on the press of a button.
  • After the creation of the new sheet I would like to also copy the supliers name to a cell in the created sheet, let's say on B1.
  • On the created sheet I would like to manually fill some cells and get those cells copied over to the Master list.

Here's the code I have so far. Thank you all
Master.png

Code:
Sub SheetsFromTemplate()
Dim wsMASTER As Worksheet, wsTEMP As Worksheet, wasVISIBLE As Boolean
Dim shNAMES As Range, Nm As Range


With ThisWorkbook                                               'mantém foco nesta folha
    Set wsTEMP = .Sheets("Template")                            'folha a ser copiada
    wasVISIBLE = (wsTEMP.Visible = xlSheetVisible)              'verificar se está oculta
    If Not wasVISIBLE Then wsTEMP.Visible = xlSheetVisible      'torná-la visível
    
    Set wsMASTER = .Sheets("Master")                            'folha mestre
                                                                'intervalo a verificar
    Set shNAMES = wsMASTER.Range("B3:B" & Rows.Count).SpecialCells(xlConstants)     'or xlFormulas
    
    Application.ScreenUpdating = False                              'acelerar macro
    For Each Nm In shNAMES                                          'verificar um nome de cada vez
        If Not Evaluate("ISREF('" & CStr(Nm.Text) & "'!A1)") Then   'se a folha ainda não existe...
            wsTEMP.Copy After:=.Sheets(.Sheets.Count)               '...criar a partir do template
            ActiveSheet.Name = CStr(Nm.Text)                        '...renomear a folha
        End If
    Next Nm
    
    wsMASTER.Activate                                           'regressar à folha mestre
    If Not wasVISIBLE Then wsTEMP.Visible = xlSheetHidden       'esconder o template se necessário
    Application.ScreenUpdating = True                           'atualizar o ecrã
End With


MsgBox "New supplier added"
End Sub
Master.png
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,214,411
Messages
6,119,360
Members
448,888
Latest member
Arle8907

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