ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   finding a tab name (https://www.excelbanter.com/excel-programming/389346-finding-tab-name.html)

tigoda

finding a tab name
 
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?


Barb Reinhardt

finding a tab name
 
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

"tigoda" wrote:

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?


tigoda

finding a tab name
 
that works perfectly, thanks!

"Barb Reinhardt" wrote:

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

"tigoda" wrote:

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?



All times are GMT +1. The time now is 08:51 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com