Insert New Worksheet based on Cell Contents...

HELP PLEASE

Board Regular
Joined
Jan 8, 2005
Messages
156
Hello all,
Cell A1 has the first three leters of the current month, then a dash and the last two letters of the current year; example (Feb-05). I need a macro that creates a new worksheet with the cell A1's contents as its name if a worksheet with that name does not already exist. Is that possible? Thanks for all your help always! Carl
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Below an other possible solution (I spent time for it, and why not to show it ?? :biggrin: )

Code:

Sub InserNewSheet()
'
'
Dim SheetExists As Worksheet
Dim SheetName As String
SheetName = ActiveSheet.Range("A1").Text
If SheetName <> "" Then
On Error Resume Next
Set SheetExists = Sheets(SheetName)
On Error GoTo 0
If SheetExists Is Nothing Then
Set SheetExists = Sheets.Add(after:=Sheets(Sheets.Count))
SheetExists.Name = SheetName
End If
End If
End Sub
 
Upvote 0
Similar to this...is there a way to make a sheet unhidden when A1 is equal to the name of the hidden sheet? Hope that makes senese...thanks so much!
 
Upvote 0
Wow! I think I got it....Thanks for your help!



Sub InserNewSheet()
'
'
Dim SheetExists As Worksheet
Dim SheetName As String
SheetName = ActiveSheet.Range("A1").Text

If SheetName <> "" Then
On Error Resume Next
Set SheetExists = Sheets(SheetName)
Sheets(SheetName).Visible = True

If SheetName <> "" Then
On Error Resume Next
Set SheetExists = Sheets(SheetName)
On Error GoTo 0

'If SheetExist Is Nothing Then
'Set Sheets(SheetName).Visible = True
'On Error GoTo 0

If SheetExists Is Nothing Then
Set SheetExists = Sheets.Add(after:=Sheets(Sheets.Count))
SheetExists.Name = SheetName
End If
End If
End If

Sheets(SheetName).Select

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,488
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top