ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Naming worksheets (https://www.excelbanter.com/excel-programming/350713-naming-worksheets.html)

simonhall[_2_]

Naming worksheets
 

Hi,

I have a macro that makes a copy of sheet2 at the end of the workbook.

Is it possible to change the name of the new workseet to the contents
of a cell in sheet1?

Thanks, Simon


--
simonhall
------------------------------------------------------------------------
simonhall's Profile: http://www.excelforum.com/member.php...o&userid=30582
View this thread: http://www.excelforum.com/showthread...hreadid=502292


Jim Thomlinson[_5_]

Naming worksheets
 
Sure. You should check to make sure that the name in the Cell will not be a
duplicate of another sheet name.

sheet2.copy After:=Sheet2
'The copied sheet is now the active sheet
With activesheet
if sheetexists(.range("A1").Text) = false then .name = .range("A1").Text
end with



Public Function SheetExists(SName As String, _
Optional ByVal Wb As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If Wb Is Nothing Then Set Wb = ThisWorkbook
SheetExists = CBool(Len(Wb.Sheets(SName).Name))
End Function
--
HTH...

Jim Thomlinson


"simonhall" wrote:


Hi,

I have a macro that makes a copy of sheet2 at the end of the workbook.

Is it possible to change the name of the new workseet to the contents
of a cell in sheet1?

Thanks, Simon


--
simonhall
------------------------------------------------------------------------
simonhall's Profile: http://www.excelforum.com/member.php...o&userid=30582
View this thread: http://www.excelforum.com/showthread...hreadid=502292




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

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