Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Naming worksheets in loop

Hi Jenni,

Try:

'=============
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim iCtr As Long
Const sName As String = "MyWorksheet" '<<==== CHANGE

Set WB = Workbooks("YourBook.xls") '<<==== CHANGE

iCtr = WB.Worksheets.Count

Set SH = Worksheets.Add(after:=Worksheets(iCtr))

SH.Name = sName & iCtr

End Sub
'<<=============


---
Regards,
Norman

"Jenni_Sweden" wrote in message
...
Hi! I am writing a macro for excel that generates new worksheets. I want
to
name the worksheets so that all worksheets has one part of their name that
is
the same for all worksheets and I want to have one variable part. My
erronous
code now is:

Set NewSheet = Worksheets.Add
NewSheet.Name = "My worksheet" + x

I want to have a counter for x but I do not know how to comine the String
part ("My worksheet") with the value of the variabel so that the final
name
is e.g. My worksheet 14. Help please!
--
I am very thankful for any fast assistance!



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
Naming new worksheets paz24 Excel Discussion (Misc queries) 0 February 1st 06 11:46 AM
Naming worksheets simonhall[_2_] Excel Programming 1 January 18th 06 01:19 AM
Naming worksheets ozcank[_18_] Excel Programming 5 June 27th 05 12:27 PM
Naming Worksheets in VBE Don Guillett[_4_] Excel Programming 0 July 18th 03 08:17 PM
Naming Worksheets in VBE Chip Pearson Excel Programming 0 July 18th 03 08:16 PM


All times are GMT +1. The time now is 05:13 PM.

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

About Us

"It's about Microsoft Excel"