PC Review


Reply
Thread Tools Rate Thread

ActiveSheet.name not returning Sheet1, Sheet2

 
 
Rebecca_SUNY
Guest
Posts: n/a
 
      10th Jul 2008
In VBE in the property window of a worksheet there is a field (Name) that
doesn't change even if the tab name or index position changes. I would like
to use this "name" and evaluate it to reset the print range. I only want to
reset the print range of Sheets "Sheet11" to "Sheet31". When I use the
ActiveSheet.Name command I only get the "tab" name, not this static name. Is
there any way to retrieve the (Name) and evaluate it. Here is the piece of
code that I am working with.

Dim SheetNum_Low As Integer
Dim SheetNum_High As Integer
Dim ws As Worksheet
Dim SheetNum As Integer

SheetNum_Low = 11
SheetNum_High = 31

For Each ws In Worksheets

ws.Activate

SheetNum = ActiveSheet.Index
SheetNum = val(left(ActiveSheet.Name,2))


If SheetNum >= SheetNum_Low And SheetNum <= SheetNum_High Then

ActiveSheet.PageSetup.PrintArea = ActiveSheet.UsedRange.Address

End If

Next


 
Reply With Quote
 
 
 
 
Tom Ogilvy
Guest
Posts: n/a
 
      10th Jul 2008
Activesheet.codename

--
Regards,
Tom Ogilvy



"Rebecca_SUNY" wrote:

> In VBE in the property window of a worksheet there is a field (Name) that
> doesn't change even if the tab name or index position changes. I would like
> to use this "name" and evaluate it to reset the print range. I only want to
> reset the print range of Sheets "Sheet11" to "Sheet31". When I use the
> ActiveSheet.Name command I only get the "tab" name, not this static name. Is
> there any way to retrieve the (Name) and evaluate it. Here is the piece of
> code that I am working with.
>
> Dim SheetNum_Low As Integer
> Dim SheetNum_High As Integer
> Dim ws As Worksheet
> Dim SheetNum As Integer
>
> SheetNum_Low = 11
> SheetNum_High = 31
>
> For Each ws In Worksheets
>
> ws.Activate
>
> SheetNum = ActiveSheet.Index
> SheetNum = val(left(ActiveSheet.Name,2))
>
>
> If SheetNum >= SheetNum_Low And SheetNum <= SheetNum_High Then
>
> ActiveSheet.PageSetup.PrintArea = ActiveSheet.UsedRange.Address
>
> End If
>
> Next
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      10th Jul 2008
That (Name) property is called the codename.

I think I'd use something like:

Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
With wks
If LCase(.CodeName) Like LCase("Sheet##") Then
Select Case CLng(Right(.CodeName, 2))
Case 11 To 31
'do the work
'MsgBox .CodeName & "--" & .Name
.PageSetup.PrintArea = .UsedRange.Address
End Select
End If
End With
Next wks

Rebecca_SUNY wrote:
>
> In VBE in the property window of a worksheet there is a field (Name) that
> doesn't change even if the tab name or index position changes. I would like
> to use this "name" and evaluate it to reset the print range. I only want to
> reset the print range of Sheets "Sheet11" to "Sheet31". When I use the
> ActiveSheet.Name command I only get the "tab" name, not this static name. Is
> there any way to retrieve the (Name) and evaluate it. Here is the piece of
> code that I am working with.
>
> Dim SheetNum_Low As Integer
> Dim SheetNum_High As Integer
> Dim ws As Worksheet
> Dim SheetNum As Integer
>
> SheetNum_Low = 11
> SheetNum_High = 31
>
> For Each ws In Worksheets
>
> ws.Activate
>
> SheetNum = ActiveSheet.Index
> SheetNum = val(left(ActiveSheet.Name,2))
>
> If SheetNum >= SheetNum_Low And SheetNum <= SheetNum_High Then
>
> ActiveSheet.PageSetup.PrintArea = ActiveSheet.UsedRange.Address
>
> End If
>
> Next


--

Dave Peterson
 
Reply With Quote
 
Rebecca_SUNY
Guest
Posts: n/a
 
      11th Jul 2008
I knew it was something easy but I just couldn't FIND it. Thanks. You went
above and beyond and it was very helpful.

I assume the Lcase is because the Like operator is case sensitive...?


"Dave Peterson" wrote:

> That (Name) property is called the codename.
>
> I think I'd use something like:
>
> Dim wks As Worksheet
> For Each wks In ActiveWorkbook.Worksheets
> With wks
> If LCase(.CodeName) Like LCase("Sheet##") Then
> Select Case CLng(Right(.CodeName, 2))
> Case 11 To 31
> 'do the work
> 'MsgBox .CodeName & "--" & .Name
> .PageSetup.PrintArea = .UsedRange.Address
> End Select
> End If
> End With
> Next wks
>
> Rebecca_SUNY wrote:
> >
> > In VBE in the property window of a worksheet there is a field (Name) that
> > doesn't change even if the tab name or index position changes. I would like
> > to use this "name" and evaluate it to reset the print range. I only want to
> > reset the print range of Sheets "Sheet11" to "Sheet31". When I use the
> > ActiveSheet.Name command I only get the "tab" name, not this static name. Is
> > there any way to retrieve the (Name) and evaluate it. Here is the piece of
> > code that I am working with.
> >
> > Dim SheetNum_Low As Integer
> > Dim SheetNum_High As Integer
> > Dim ws As Worksheet
> > Dim SheetNum As Integer
> >
> > SheetNum_Low = 11
> > SheetNum_High = 31
> >
> > For Each ws In Worksheets
> >
> > ws.Activate
> >
> > SheetNum = ActiveSheet.Index
> > SheetNum = val(left(ActiveSheet.Name,2))
> >
> > If SheetNum >= SheetNum_Low And SheetNum <= SheetNum_High Then
> >
> > ActiveSheet.PageSetup.PrintArea = ActiveSheet.UsedRange.Address
> >
> > End If
> >
> > Next

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      11th Jul 2008
That's what I would assume, too <vbg>.

But it wouldn't take much to test it to confirm or reject that assumption!

Rebecca_SUNY wrote:
>
> I knew it was something easy but I just couldn't FIND it. Thanks. You went
> above and beyond and it was very helpful.
>
> I assume the Lcase is because the Like operator is case sensitive...?
>
> "Dave Peterson" wrote:
>
> > That (Name) property is called the codename.
> >
> > I think I'd use something like:
> >
> > Dim wks As Worksheet
> > For Each wks In ActiveWorkbook.Worksheets
> > With wks
> > If LCase(.CodeName) Like LCase("Sheet##") Then
> > Select Case CLng(Right(.CodeName, 2))
> > Case 11 To 31
> > 'do the work
> > 'MsgBox .CodeName & "--" & .Name
> > .PageSetup.PrintArea = .UsedRange.Address
> > End Select
> > End If
> > End With
> > Next wks
> >
> > Rebecca_SUNY wrote:
> > >
> > > In VBE in the property window of a worksheet there is a field (Name) that
> > > doesn't change even if the tab name or index position changes. I would like
> > > to use this "name" and evaluate it to reset the print range. I only want to
> > > reset the print range of Sheets "Sheet11" to "Sheet31". When I use the
> > > ActiveSheet.Name command I only get the "tab" name, not this static name. Is
> > > there any way to retrieve the (Name) and evaluate it. Here is the piece of
> > > code that I am working with.
> > >
> > > Dim SheetNum_Low As Integer
> > > Dim SheetNum_High As Integer
> > > Dim ws As Worksheet
> > > Dim SheetNum As Integer
> > >
> > > SheetNum_Low = 11
> > > SheetNum_High = 31
> > >
> > > For Each ws In Worksheets
> > >
> > > ws.Activate
> > >
> > > SheetNum = ActiveSheet.Index
> > > SheetNum = val(left(ActiveSheet.Name,2))
> > >
> > > If SheetNum >= SheetNum_Low And SheetNum <= SheetNum_High Then
> > >
> > > ActiveSheet.PageSetup.PrintArea = ActiveSheet.UsedRange.Address
> > >
> > > End If
> > >
> > > Next

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
Rebecca_SUNY
Guest
Posts: n/a
 
      11th Jul 2008
Excel Help says Like is case INsensitive when comparing text, but that is not
how it tested. I tried it without the Lcase and changed it to "sheet##" and
it returned false. Best to leave the lcase in. good tip.

"Dave Peterson" wrote:

> That's what I would assume, too <vbg>.
>
> But it wouldn't take much to test it to confirm or reject that assumption!
>
> Rebecca_SUNY wrote:
> >
> > I knew it was something easy but I just couldn't FIND it. Thanks. You went
> > above and beyond and it was very helpful.
> >
> > I assume the Lcase is because the Like operator is case sensitive...?
> >
> > "Dave Peterson" wrote:
> >
> > > That (Name) property is called the codename.
> > >
> > > I think I'd use something like:
> > >
> > > Dim wks As Worksheet
> > > For Each wks In ActiveWorkbook.Worksheets
> > > With wks
> > > If LCase(.CodeName) Like LCase("Sheet##") Then
> > > Select Case CLng(Right(.CodeName, 2))
> > > Case 11 To 31
> > > 'do the work
> > > 'MsgBox .CodeName & "--" & .Name
> > > .PageSetup.PrintArea = .UsedRange.Address
> > > End Select
> > > End If
> > > End With
> > > Next wks
> > >
> > > Rebecca_SUNY wrote:
> > > >
> > > > In VBE in the property window of a worksheet there is a field (Name) that
> > > > doesn't change even if the tab name or index position changes. I would like
> > > > to use this "name" and evaluate it to reset the print range. I only want to
> > > > reset the print range of Sheets "Sheet11" to "Sheet31". When I use the
> > > > ActiveSheet.Name command I only get the "tab" name, not this static name. Is
> > > > there any way to retrieve the (Name) and evaluate it. Here is the piece of
> > > > code that I am working with.
> > > >
> > > > Dim SheetNum_Low As Integer
> > > > Dim SheetNum_High As Integer
> > > > Dim ws As Worksheet
> > > > Dim SheetNum As Integer
> > > >
> > > > SheetNum_Low = 11
> > > > SheetNum_High = 31
> > > >
> > > > For Each ws In Worksheets
> > > >
> > > > ws.Activate
> > > >
> > > > SheetNum = ActiveSheet.Index
> > > > SheetNum = val(left(ActiveSheet.Name,2))
> > > >
> > > > If SheetNum >= SheetNum_Low And SheetNum <= SheetNum_High Then
> > > >
> > > > ActiveSheet.PageSetup.PrintArea = ActiveSheet.UsedRange.Address
> > > >
> > > > End If
> > > >
> > > > Next
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      11th Jul 2008
Doesn't VBA's help state that it's not case sensitive if "option compare text"
is used?

Rebecca_SUNY wrote:
>
> Excel Help says Like is case INsensitive when comparing text, but that is not
> how it tested. I tried it without the Lcase and changed it to "sheet##" and
> it returned false. Best to leave the lcase in. good tip.
>
> "Dave Peterson" wrote:
>
> > That's what I would assume, too <vbg>.
> >
> > But it wouldn't take much to test it to confirm or reject that assumption!
> >
> > Rebecca_SUNY wrote:
> > >
> > > I knew it was something easy but I just couldn't FIND it. Thanks. You went
> > > above and beyond and it was very helpful.
> > >
> > > I assume the Lcase is because the Like operator is case sensitive...?
> > >
> > > "Dave Peterson" wrote:
> > >
> > > > That (Name) property is called the codename.
> > > >
> > > > I think I'd use something like:
> > > >
> > > > Dim wks As Worksheet
> > > > For Each wks In ActiveWorkbook.Worksheets
> > > > With wks
> > > > If LCase(.CodeName) Like LCase("Sheet##") Then
> > > > Select Case CLng(Right(.CodeName, 2))
> > > > Case 11 To 31
> > > > 'do the work
> > > > 'MsgBox .CodeName & "--" & .Name
> > > > .PageSetup.PrintArea = .UsedRange.Address
> > > > End Select
> > > > End If
> > > > End With
> > > > Next wks
> > > >
> > > > Rebecca_SUNY wrote:
> > > > >
> > > > > In VBE in the property window of a worksheet there is a field (Name) that
> > > > > doesn't change even if the tab name or index position changes. I would like
> > > > > to use this "name" and evaluate it to reset the print range. I only want to
> > > > > reset the print range of Sheets "Sheet11" to "Sheet31". When I use the
> > > > > ActiveSheet.Name command I only get the "tab" name, not this static name. Is
> > > > > there any way to retrieve the (Name) and evaluate it. Here is the piece of
> > > > > code that I am working with.
> > > > >
> > > > > Dim SheetNum_Low As Integer
> > > > > Dim SheetNum_High As Integer
> > > > > Dim ws As Worksheet
> > > > > Dim SheetNum As Integer
> > > > >
> > > > > SheetNum_Low = 11
> > > > > SheetNum_High = 31
> > > > >
> > > > > For Each ws In Worksheets
> > > > >
> > > > > ws.Activate
> > > > >
> > > > > SheetNum = ActiveSheet.Index
> > > > > SheetNum = val(left(ActiveSheet.Name,2))
> > > > >
> > > > > If SheetNum >= SheetNum_Low And SheetNum <= SheetNum_High Then
> > > > >
> > > > > ActiveSheet.PageSetup.PrintArea = ActiveSheet.UsedRange.Address
> > > > >
> > > > > End If
> > > > >
> > > > > Next
> > > >
> > > > --
> > > >
> > > > Dave Peterson
> > > >

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy data from sheet2 to sheet1 when sheet2 has variable # of rows Anne Microsoft Excel Misc 6 27th Feb 2009 09:48 PM
A1 Sheet2 is linked to A1 sheet1 so that user enters value(abc123) a1 sheet1 and A1 sheet2 is updated pano Microsoft Excel Programming 2 28th Oct 2007 02:32 PM
how do copy "sheet1!A1+1 in sheet2 to sheet 3 and get "sheet2!A1+ =?Utf-8?B?RGFueQ==?= Microsoft Excel Misc 5 16th Apr 2007 03:27 AM
go to sheet1 to sheet2 braddy Microsoft Excel Programming 1 20th Sep 2005 06:18 AM
Show a sheet1 row in sheet2 based on values in col sheet1.A =?Utf-8?B?TWljaGVsbGU=?= Microsoft Excel Misc 5 4th Mar 2004 02:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:58 PM.