Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-23-2015, 08:23 AM
FenelonPaul FenelonPaul is offline New Sheet naming Windows 8 New Sheet naming Office 2013
Novice
New Sheet naming
 
Join Date: Sep 2015
Posts: 6
FenelonPaul is on a distinguished road
Default New Sheet naming

I am trying to record a macro that deletes a sheet and creates a new one.

The problem is that excel renames sheets.. if I create a new one the first time, it calls it sheet1; if I delete it and create a new one again, it calls it sheet2.

This really messes up the macro, and it mis-references the sheet because the name has changed. I can't even rename the sheet, because it can't find the original sheet1.

Is there any way around this?
Reply With Quote
  #2  
Old 09-23-2015, 09:23 AM
NoSparks NoSparks is offline New Sheet naming Windows 7 64bit New Sheet naming Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

The instant the new sheet is created it is the activesheet so on the next line of code
activesheet.name = "Sheet1" should rename it to Sheet1.

Myself, probably wouldn't delete the original sheet, would use .cells.delete to just clear everything from the sheet. It would then be blank same as the added sheet would be.

Seeing you're using the macro recorder this would be clicking the square above the row numbers which selects all cells then hitting delete.
Reply With Quote
  #3  
Old 09-23-2015, 11:02 AM
charlesdh charlesdh is offline New Sheet naming Windows 7 32bit New Sheet naming Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

Hi,

Here's a simple code to add and name a worksheet also delete the named worksheet.
Place this code in a module. Test on sample sheet ony.


Code:
Sub AddWorksheet()
Application.DisplayAlerts = False'' this will prevent warning about deleting the sheet
Sheets("Your sheet name").Delete
Application.DisplayAlerts = True ''this will reset the warning

Worksheets.Add().Name = "MySheet"''' change "MySheet to the name you want

End Sub
Reply With Quote
  #4  
Old 09-24-2015, 07:57 AM
FenelonPaul FenelonPaul is offline New Sheet naming Windows 8 New Sheet naming Office 2013
Novice
New Sheet naming
 
Join Date: Sep 2015
Posts: 6
FenelonPaul is on a distinguished road
Default Thanks!!!

Thanks, Charles.. that works perfectly for me!
Reply With Quote
  #5  
Old 09-24-2015, 09:44 AM
charlesdh charlesdh is offline New Sheet naming Windows 7 32bit New Sheet naming Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

Thanks for the update. You can mark this as solved.
Reply With Quote
  #6  
Old 09-24-2015, 10:28 AM
FenelonPaul FenelonPaul is offline New Sheet naming Windows 8 New Sheet naming Office 2013
Novice
New Sheet naming
 
Join Date: Sep 2015
Posts: 6
FenelonPaul is on a distinguished road
Default

Quote:
Originally Posted by charlesdh View Post
Thanks for the update. You can mark this as solved.
uh.. ok.. how?
Reply With Quote
  #7  
Old 09-24-2015, 10:33 AM
charlesdh charlesdh is offline New Sheet naming Windows 7 32bit New Sheet naming Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

Hi,

Click on "Thread Tools". You will see it.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch re-naming twols26 Word VBA 7 06-16-2015 12:29 PM
Populate sheet 3 with data from sheet 1 and sheet 2 speck Excel Programming 0 01-14-2015 07:54 AM
Naming Cells for formula referencing lynchbro Excel 6 06-26-2014 07:45 AM
New Sheet naming re-naming arrays in VBA? JDevsFan Excel Programming 4 03-15-2012 08:44 AM
Auto file naming Rong Peng Word VBA 0 07-29-2011 07:37 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:17 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft