Maintain/create many sheets

kevinboo

Board Regular
Joined
Nov 8, 2004
Messages
146
Hi All,

Need a little help. I did, some time ago obtain the code below, this automatically created, and maintained/updated many sheets from a Master sheet, but I now need a tweek.

When I origionally used this code the list of items on the Master were static, in that once the individual sheet had been created, only certain fields for the item on the master changed, but no additional lines were added to or taken away from the master.

Now I need to add lines to the master possibly on a daily basis, and have this change reflected on the individual sheets. The individual sheets (so the names in B2:B in the macro) are place names, so what I want is;
  • If a sheet for say 'France' already exists, and I then add another line for France on the master, for the individual 'France' sheet to reflect this change.
  • But if I add a line for say 'Britain' and no data for 'Britian' exists on the master, then I want it to create an individual sheet for 'Britian' and reflect the detail on the Master, anybody???
Origional code below;

This will <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
  • Create a new sheet<o:p></o:p>
  • Pull all the info from the specific ‘Name”<o:p></o:p>
  • Will update on opening<o:p></o:p>
<o:p> </o:p>
All the info from a ‘Master’ Worksheet<o:p></o:p>
<o:p> </o:p>
A couple of things<o:p></o:p>
<o:p> </o:p>
  • The B2:B below points to the column that the ‘Names’ for the worksheets to be created are in .<o:p></o:p>
  • Paste both macros into the workbook specific<o:p></o:p>
<o:p> </o:p>
Sub xxx()
Dim iCol As Integer, iColEnd As Integer
Dim lRow As Long
Dim rMaster As Range, R As Range
Dim sCur As String, sMess As String
Dim wsMaster As Worksheet
Dim wsTarget As Worksheet
<o:p> </o:p>
Set wsMaster = Sheets("Master")
Set rMaster = wsMaster.Range("B2:B" & wsMaster.UsedRange.Rows.Count)
iColEnd = wsMaster.UsedRange.Columns.Count
<o:p> </o:p>
'***************************************
'** first ensure that all sheets exist **
'***************************************
For Each R In rMaster
sCur = R.Text
On Error Resume Next
Set wsTarget = Sheets(sCur)
If Err.Number > 0 Then
Sheets.Add after:=Sheets(Sheets.Count)
Err.Number = 0
Sheets(Sheets.Count).Name = sCur
If Err.Number > 0 Then
MsgBox "Row " & R.Row & " has an illegal character in the name." & vbCrLf & _
"Please correct."
Exit Sub
End If
End If
On Error GoTo 0
Next R
<o:p> </o:p>
'*******************************************
'** Loop thru all entries in Master sheet **
'*******************************************
For Each R In rMaster
sCur = R.Text
Set wsTarget = Sheets(sCur)
lRow = wsTarget.Range("A65536").End(xlUp).Row + 1
For iCol = 1 To iColEnd
wsTarget.Cells(lRow, iCol).FormulaR1C1 = "='" & wsMaster.Name & _
"'!R" & R.Row & "C" & iCol
Next iCol
Next R
End Sub
<o:p> </o:p>
This code make it update on opening<o:p></o:p>
<o:p> </o:p>
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If ActiveSheet.Name = "Master" Then Exit Sub
xxx
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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