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
 

Some videos you may like

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

chiello

Well-known Member
Joined
Jan 18, 2005
Messages
848
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
 

HELP PLEASE

Board Regular
Joined
Jan 8, 2005
Messages
156
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!
 

HELP PLEASE

Board Regular
Joined
Jan 8, 2005
Messages
156
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,213
Messages
5,594,874
Members
413,945
Latest member
V51773

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
Top