G
Guest
Dear All
I'm struggling with working out if a sheet exists in my workbook. I've used
code posted from this group but need to tweek it to create a sheet name based
on a couple of cell values. When I use the code below, Run Time Error 9 is
returned.
myShtName creates a string 'prd1 Product Name' - this is the sheet name I'm
looking for - if it exists then no action is needed, otherwise copy a
template sheet at the end of the workbook, and name the sheet 'prd1 Product
Name'.
As usual, any help gratefully appreciated
Trevor.
--------------------------------------
Dim rng As Range, cell As Range
Dim ws As Workksheet
Dim myShtName As String
Set rng = Range("productlist")
For Each cell In rng
If cell <> "" Then
myShtName = "prd" & cell.Offset(0, -1).Value & " " & cell.Value
Set ws = Worksheets(myShtName)
If ws Is Nothing Then
Sheets("Product Template").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = myShtName
Range("B3") = cell.Value
End If
End If
Next cell
I'm struggling with working out if a sheet exists in my workbook. I've used
code posted from this group but need to tweek it to create a sheet name based
on a couple of cell values. When I use the code below, Run Time Error 9 is
returned.
myShtName creates a string 'prd1 Product Name' - this is the sheet name I'm
looking for - if it exists then no action is needed, otherwise copy a
template sheet at the end of the workbook, and name the sheet 'prd1 Product
Name'.
As usual, any help gratefully appreciated
Trevor.
--------------------------------------
Dim rng As Range, cell As Range
Dim ws As Workksheet
Dim myShtName As String
Set rng = Range("productlist")
For Each cell In rng
If cell <> "" Then
myShtName = "prd" & cell.Offset(0, -1).Value & " " & cell.Value
Set ws = Worksheets(myShtName)
If ws Is Nothing Then
Sheets("Product Template").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = myShtName
Range("B3") = cell.Value
End If
End If
Next cell