Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Adding a sheet with a specific name

I need a macro that will take the name in cell A2 and see if there is a sheet
that already has that name. If there is not a sheet then I need it to create
a new sheet with the name as the name of the sheet. Is this possible?

my macro right now just searches for a sheet with the same name.

If Cells(1, 2).Value < "" Then
name = Cells(1, 2).Value
Sheets(name).Activate

how can I add the creating new sheet part?

Thanks,
Kyle
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Adding a sheet with a specific name

Pass the value to this sub:

Public Sub CreateSheet(SheetName As String)
'
' if the sheet already exists select it
'
On Error GoTo CreateNewSheet
Sheets(SheetName).Select
Exit Sub
'
' if not create it
'
CreateNewSheet:
Sheets.Add After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = SheetName
'
End Sub


"kyle" wrote:

I need a macro that will take the name in cell A2 and see if there is a sheet
that already has that name. If there is not a sheet then I need it to create
a new sheet with the name as the name of the sheet. Is this possible?

my macro right now just searches for a sheet with the same name.

If Cells(1, 2).Value < "" Then
name = Cells(1, 2).Value
Sheets(name).Activate

how can I add the creating new sheet part?

Thanks,
Kyle

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Adding a sheet with a specific name


Charlie wrote:
Pass the value to this sub:

Public Sub CreateSheet(SheetName As String)
'
' if the sheet already exists select it
'
On Error GoTo CreateNewSheet
Sheets(SheetName).Select
Exit Sub
'
' if not create it
'
CreateNewSheet:
Sheets.Add After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = SheetName
'
End Sub


"kyle" wrote:

I need a macro that will take the name in cell A2 and see if there is a sheet
that already has that name. If there is not a sheet then I need it to create
a new sheet with the name as the name of the sheet. Is this possible?

my macro right now just searches for a sheet with the same name.

If Cells(1, 2).Value < "" Then
name = Cells(1, 2).Value
Sheets(name).Activate

how can I add the creating new sheet part?

Thanks,
Kyle


Hi

Try this code

Sub Create_Sheets()

Dim Name As String
Dim Sheet_Count As Integer
Dim Wk_Sheet As Worksheet
Dim Check As Boolean

Name = ThisWorkbook.Sheets("Sheet1").Range("A2").Value
Sheet_Count = Worksheets.Count

For Each Wk_Sheet In ThisWorkbook.Sheets
If Wk_Sheet.Name = Name Then
Check = True
End If
Next

'if there is no sheet found
If Check = False Then
'Add the sheet at last
ThisWorkbook.Sheets.Add after:=Worksheets(Worksheets.Count)
ThisWorkbook.Sheets(Sheet_Count + 1).Name =
ThisWorkbook.Sheets(1).Range("a2").Value
End If

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Only adding up specific categories [email protected] Excel Discussion (Misc queries) 5 October 23rd 06 09:32 PM
adding specific cells Shooter Excel Worksheet Functions 1 January 23rd 06 04:42 PM
Adding specific Cells Only. Lost at Sea Excel Discussion (Misc queries) 2 August 22nd 05 08:04 PM
Adding specific rows together rxwillow[_3_] Excel Programming 5 January 25th 04 10:51 PM
Adding New Wo&#305;kbook with a specific name Tolga & Hande Excel Programming 2 October 6th 03 10:34 PM


All times are GMT +1. The time now is 03:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"