Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Filling cells

Hi all,

I have a workbook that adds worksheets, names them and sorts them. I need to
show these worksheets as Sheet 1 of 1 and if necessary Sheet 1 of 2 and Sheet
2 of 2. When it adds the worksheets it names them based on a cell entry, so I
will have something like: DBL ARROW for worksheet1 name and it would be Sheet
1 of 1, if I need another sheet with the same name it would be DBL ARROW (2).
So I would now want DBL ARROW to be Sheet 1 of 2 and DBL ARROW (2) to be
Sheet 2 of 2, then if I added another sheet named 4" Yellow it would be Sheet
1 of 1 and so on. Is there a way to do this? I have ranges named Sht_of_ and
Sht_of_1 for the numbers.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Filling cells



Public Sub AddWorkbook(nameInCell As String)
Dim wb As Workbook
Dim ws, cs As Worksheet
Dim v, x, y, z As Integer
Set wb = ThisWorkbook
x = wb.Worksheets.Count
z = 0
For y = 1 To x Step 1
If Left(wb.Sheets(y).Name, Len(nameInCell)) = nameInCell Then
z = z + 1
Set cs = wb.Sheets(y)
End If
Next y
cs.Activate
If z = 1 Then
z = z + 1
Set ws = wb.Sheets.Add(after:=cs)
ws.Name = Left(cs.Name, Len(nameInCell)) & " - " & LTrim(Str(z)) & "
of " & LTrim(Str(z))
v = z - 1
For y = (x + 1) To 1 Step -1
Set cs = wb.Sheets(y)
If Left(cs.Name, Len(nameInCell)) = Left(ws.Name,
Len(nameInCell)) And cs.Name < ws.Name Then
wb.Sheets(y).Name = nameInCell & " - " & LTrim(Str(v)) & "
of " & LTrim(Str(z))
v = v - 1
End If
Next
Else
wb.Sheets.Add after:=Worksheets(Worksheets.Count)
End If
Set cs = Nothing
Set ws = Nothing
Set wb = Nothing
End Sub


If there's a 'Sheet 1 of 1', the above thing wants to have that sheetname
and 'Sheet 2 of 2' will be added after 'Sheet 1 of 1'.
After that, 'Sheet 1 of 1' is also renamed to 'Sheet 1 of 2'.


You can pass the sheetname to the macro using a
Worksheet_BeforeDoubleClick-event.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
AddWorkbook (Target.Value)
End Sub


I hope this is what you want, but I liked to figure it out anyway if it's
not.



"jnf40" schreef in bericht
...
Hi all,

I have a workbook that adds worksheets, names them and sorts them. I need
to
show these worksheets as Sheet 1 of 1 and if necessary Sheet 1 of 2 and
Sheet
2 of 2. When it adds the worksheets it names them based on a cell entry,
so I
will have something like: DBL ARROW for worksheet1 name and it would be
Sheet
1 of 1, if I need another sheet with the same name it would be DBL ARROW
(2).
So I would now want DBL ARROW to be Sheet 1 of 2 and DBL ARROW (2) to be
Sheet 2 of 2, then if I added another sheet named 4" Yellow it would be
Sheet
1 of 1 and so on. Is there a way to do this? I have ranges named Sht_of_
and
Sht_of_1 for the numbers.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Filling cells

Moon thank you for your response...the code you gave actually names the
sheets 1 of 2 and 2 of 2. I didn't explain myself too well. My sheet names
are fine as they are with the cell entry...where i need the sheet 1 of 1 is
in cells in the worksheet. On the worksheet itself I have a cell with 'Sheet'
in it then a blank cell named Sht_of_ , the next cell has 'of' in it then a
blank cell named Sht_of_1. I hope this explains it better.

"jnf40" wrote:

Hi all,

I have a workbook that adds worksheets, names them and sorts them. I need to
show these worksheets as Sheet 1 of 1 and if necessary Sheet 1 of 2 and Sheet
2 of 2. When it adds the worksheets it names them based on a cell entry, so I
will have something like: DBL ARROW for worksheet1 name and it would be Sheet
1 of 1, if I need another sheet with the same name it would be DBL ARROW (2).
So I would now want DBL ARROW to be Sheet 1 of 2 and DBL ARROW (2) to be
Sheet 2 of 2, then if I added another sheet named 4" Yellow it would be Sheet
1 of 1 and so on. Is there a way to do this? I have ranges named Sht_of_ and
Sht_of_1 for the numbers.

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
Filling in blank cells with information from cells above it tracytracy123 Excel Discussion (Misc queries) 1 June 22nd 09 11:04 PM
filling cells Art Excel Discussion (Misc queries) 0 November 30th 06 03:36 PM
filling cells widman Excel Discussion (Misc queries) 0 November 29th 06 07:29 PM
filling cells Art Excel Discussion (Misc queries) 0 November 29th 06 06:35 PM
Filling cells JohnS Excel Programming 2 September 30th 04 09:07 AM


All times are GMT +1. The time now is 09:37 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"