Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Change Code to Match Tab Name? Is this an okay idea?

shtSup1.Names.Add Name:="Sup1_BCAPA_Ratings",
RefersTo:=Range("Arrow!$C$6,Arrow!$C$16,Arrow!$C$2 3,Arrow!$C$36,Arrow!$C$56"), Visible:=True

I have many lines of code that looks similar to the above line and I have
built a workbook template that I copy over to create a new tool for the end
user. Each time most of the worksheet names change and then I have to go
into the code and update the ranges to match.
My question is if I change the worksheet (tab) names can the code change to
reflect those changes. For example, rather than have Arrow in the above code
can there be a reference to the worksheet name so that anytime the workbook
sheet names are updated then the code changes accordingly. Seems to me this
would save time in updating the code each time the workbook is copied over.
Can I then protect worksheet names so other people cannot randomly change the
names?

Or is this a bad idea to code in this way?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Change Code to Match Tab Name? Is this an okay idea?

If I were you, I'd define a static worksheet code name for the worksheet
Arrow so that you can change the worksheet name. If you view source for the
worksheet in question, you can change the Name in the properties for the
sheet.

Your code will get considerably more complicated, but it can be done like
this. Let's say the worksheet CODENAME is now Arrow. To get this piece of
it, you'd need to do this

Arrow!$C$6
Arrow.codename & "!$C$6"

If you need more help, come back.

HTH,
Barb Reinhardt

"Walter" wrote:

shtSup1.Names.Add Name:="Sup1_BCAPA_Ratings",
RefersTo:=Range("Arrow!$C$6,Arrow!$C$16,Arrow!$C$2 3,Arrow!$C$36,Arrow!$C$56"), Visible:=True

I have many lines of code that looks similar to the above line and I have
built a workbook template that I copy over to create a new tool for the end
user. Each time most of the worksheet names change and then I have to go
into the code and update the ranges to match.
My question is if I change the worksheet (tab) names can the code change to
reflect those changes. For example, rather than have Arrow in the above code
can there be a reference to the worksheet name so that anytime the workbook
sheet names are updated then the code changes accordingly. Seems to me this
would save time in updating the code each time the workbook is copied over.
Can I then protect worksheet names so other people cannot randomly change the
names?

Or is this a bad idea to code in this way?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Change Code to Match Tab Name? Is this an okay idea?

Correction. If the worksheet codename is Arrow, you'd need to do this

"'" & Arrow.name & "'!$C$6"

I always put single quotes around the name becuase I never know if the name
will have spaces or not.

"Barb Reinhardt" wrote:

If I were you, I'd define a static worksheet code name for the worksheet
Arrow so that you can change the worksheet name. If you view source for the
worksheet in question, you can change the Name in the properties for the
sheet.

Your code will get considerably more complicated, but it can be done like
this. Let's say the worksheet CODENAME is now Arrow. To get this piece of
it, you'd need to do this

Arrow!$C$6
Arrow.codename & "!$C$6"

If you need more help, come back.

HTH,
Barb Reinhardt

"Walter" wrote:

shtSup1.Names.Add Name:="Sup1_BCAPA_Ratings",
RefersTo:=Range("Arrow!$C$6,Arrow!$C$16,Arrow!$C$2 3,Arrow!$C$36,Arrow!$C$56"), Visible:=True

I have many lines of code that looks similar to the above line and I have
built a workbook template that I copy over to create a new tool for the end
user. Each time most of the worksheet names change and then I have to go
into the code and update the ranges to match.
My question is if I change the worksheet (tab) names can the code change to
reflect those changes. For example, rather than have Arrow in the above code
can there be a reference to the worksheet name so that anytime the workbook
sheet names are updated then the code changes accordingly. Seems to me this
would save time in updating the code each time the workbook is copied over.
Can I then protect worksheet names so other people cannot randomly change the
names?

Or is this a bad idea to code in this way?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,722
Default Change Code to Match Tab Name? Is this an okay idea?

Each sheet has a hard code value (visible in the VBA navigation box. Assuming
Sheet named "Arrow" is actually Sheet1, should be able to change this to:

shtSup1.Names.Add Name:="Sup1_BCAPA_Ratings",
RefersTo:=Range(Sheet1.Name & "!$C$6," & Sheet1.Name & "!$C$16," &
Sheet1.Name & "!$C$23," & Sheet1.Name & "!$C$36," & Sheet1.Name & "!$C$56"),
Visible:=True
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Walter" wrote:

shtSup1.Names.Add Name:="Sup1_BCAPA_Ratings",
RefersTo:=Range("Arrow!$C$6,Arrow!$C$16,Arrow!$C$2 3,Arrow!$C$36,Arrow!$C$56"), Visible:=True

I have many lines of code that looks similar to the above line and I have
built a workbook template that I copy over to create a new tool for the end
user. Each time most of the worksheet names change and then I have to go
into the code and update the ranges to match.
My question is if I change the worksheet (tab) names can the code change to
reflect those changes. For example, rather than have Arrow in the above code
can there be a reference to the worksheet name so that anytime the workbook
sheet names are updated then the code changes accordingly. Seems to me this
would save time in updating the code each time the workbook is copied over.
Can I then protect worksheet names so other people cannot randomly change the
names?

Or is this a bad idea to code in this way?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Change Code to Match Tab Name? Is this an okay idea?

Is arrow the name of the shtSup1 sheet?

if yes:

set shtsup1 = worksheets("Arrow")
with shtsup1
.range("c6,c16,c23,c36,c56").name = "'" & .name & "'!Supl_BCAPA_Ratings"
end with




Walter wrote:

shtSup1.Names.Add Name:="Sup1_BCAPA_Ratings",
RefersTo:=Range("Arrow!$C$6,Arrow!$C$16,Arrow!$C$2 3,Arrow!$C$36,Arrow!$C$56"), Visible:=True

I have many lines of code that looks similar to the above line and I have
built a workbook template that I copy over to create a new tool for the end
user. Each time most of the worksheet names change and then I have to go
into the code and update the ranges to match.
My question is if I change the worksheet (tab) names can the code change to
reflect those changes. For example, rather than have Arrow in the above code
can there be a reference to the worksheet name so that anytime the workbook
sheet names are updated then the code changes accordingly. Seems to me this
would save time in updating the code each time the workbook is copied over.
Can I then protect worksheet names so other people cannot randomly change the
names?

Or is this a bad idea to code in this way?


--

Dave Peterson


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
Run VBA code only worksheet change, but don't trigger worksheet_change event based on what the code does ker_01 Excel Programming 6 October 3rd 08 09:45 PM
Code to change code in a sheet and workbook module Otto Moehrbach Excel Programming 11 November 11th 07 07:20 PM
+++Help me with a loop... I have no idea what code I need! Adeptus - ExcelForums.com Excel Programming 1 August 12th 05 04:25 AM
Any Idea on how to modify this code relating to query??? hce[_24_] Excel Programming 1 October 14th 04 12:27 PM
Match Code Todd Huttenstine Excel Programming 1 March 7th 04 03:50 AM


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