Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Sheet vs. Worksheets

I'm trying to avoid potential problems caused by the change of the name or
moving of my sheets. How can I refer to a sheet regardles its name or
position.
The VBA project explorer refers to sheets as Sheet1, Sheet2 and so on.
How can I do the same in my code?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Sheet vs. Worksheets

Sheets are identified either by their name or position. If you need to
change both, consider putting a unique marker in a specific cell. You can
then search the sheets, looking for the marker.
--
Gary''s Student - gsnu200741


"LuisE" wrote:

I'm trying to avoid potential problems caused by the change of the name or
moving of my sheets. How can I refer to a sheet regardles its name or
position.
The VBA project explorer refers to sheets as Sheet1, Sheet2 and so on.
How can I do the same in my code?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Sheet vs. Worksheets

Inside your project, you can use that same Codename.

If you have a worksheet that has a codename of Sheet1, then no matter what the
Name of the worksheet is (on the bottom tab in excel), you can refer to it by
something like:

Sheet1.Range("a1").value = "hi"

In fact, you may find that it makes your coding life easier/more understandable
if you change the codename to something significant.

Inside the VBE
Show the project explorer
Select your sheet.
Hit F4 to view its properties
Change the (Name) property to something that makes sense in your code.
(Like Prices)

The Name (without the ()'s) is the name the user sees on the worksheet tab.

Then your code could look like:

Dim Res as Variant
res = application.vlookup(somevalue, prices.range("a:e"),3,false)
if iserror(res) then
'not found
else
msgbox res
end if



LuisE wrote:

I'm trying to avoid potential problems caused by the change of the name or
moving of my sheets. How can I refer to a sheet regardles its name or
position.
The VBA project explorer refers to sheets as Sheet1, Sheet2 and so on.
How can I do the same in my code?


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Sheet vs. Worksheets

Instead of using, for example, Worksheets("Sheet1"), you can use just
Sheet1.

So
x = Sheet1.Cells(1, 2).Value
will work even if the worksheet is renamed while
x = Worksheet("Sheet1").Cells(1, 2).Value
will not.




On Sun, 2 Sep 2007 08:02:00 -0700, LuisE wrote:

I'm trying to avoid potential problems caused by the change of the name or
moving of my sheets. How can I refer to a sheet regardles its name or
position.
The VBA project explorer refers to sheets as Sheet1, Sheet2 and so on.
How can I do the same in my code?


Richard
--
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
combining worksheets into one sheet JBeaucaire[_90_] Excel Worksheet Functions 0 February 4th 09 10:41 PM
list sheet 1 - same cell (eg A1) in a group of worksheets sheet Helen B Excel Worksheet Functions 2 February 10th 08 12:51 AM
Sum totals of 55 worksheets on Sheet 55? L. S. Martin Excel Worksheet Functions 3 August 27th 07 07:50 PM
Max Value Across Worksheets Returning Sheet Name [email protected] Excel Discussion (Misc queries) 2 June 13th 07 01:01 PM
re-order worksheets by sheet name Julia Chromicz Excel Programming 4 November 29th 04 11:03 PM


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