Excel Worksheet Names

  • Thread starter Thread starter jrp7286
  • Start date Start date
J

jrp7286

Does anyone know how to name a worksheet based on a row in a specific
worksheet. I have a listing of about 300 items and I need to create a
worksheet for each of these items.
 
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H1" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Me.Name = .Value
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
You don't have the sheets created yet and you want to create a new sheet for
each name in a range?

You say your "row" has about 300 items.

Are you using Excel 2007?

If not, the maximum items in a row can be 256.

This macro will create a new sheet for each name in row 1 from A1:IV1 in Sheet1

If using 2007, expand the range to suit.

Sub Add_Sheets22()
Dim rCell As Range
For Each rCell In Sheets("Sheet1").Range("A1:IV1")
With Worksheets.Add(After:=Worksheets(Worksheets.Count))
.Name = rCell.Value
End With
Next rCell
End Sub


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top