finding a tab name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a list of tab names and data, I can set a string as the tab name and
go to it using

Sheets(S1).Select

However, if the tab is not found I need to create it, how can this be done?
 
Try something like this

Dim s1 As String
Dim WS As Worksheet

s1 = "TEST"

Set WS = Nothing
On Error Resume Next
Set WS = Sheets(s1)
On Error GoTo 0

If WS Is Nothing Then
Set WS = Worksheets.Add(After:=Worksheets(Worksheets.Count))
WS.Name = s1
End If


HTH,
Barb Reinhardt
 
that works perfectly, thanks!

Barb Reinhardt said:
Try something like this

Dim s1 As String
Dim WS As Worksheet

s1 = "TEST"

Set WS = Nothing
On Error Resume Next
Set WS = Sheets(s1)
On Error GoTo 0

If WS Is Nothing Then
Set WS = Worksheets.Add(After:=Worksheets(Worksheets.Count))
WS.Name = s1
End If


HTH,
Barb Reinhardt
 

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