Re: VBA CODE for Excel 2007 & 2010
You can use the sheet index:
In your workbook, as it's set up right now...with Sheet 1 on the left and sheet 2 on the right you could use:
Sheets(1) for sheet1, and Sheets(2) for sheet2. However, if you move the sheets around or add sheets, that may change. Sheet index is always from left to right. Sheets(1) right now, is sheet1....if you move sheet2 to the left of sheet1, then Sheets(1) would refer to sheet2. So you have to be careful, but yes it does remove sheet name problems. Index doesn't care what the name is.
OR :)....there's always an or....
You can use the sheet codename:
As it is right now:
Sheets("Sheet1").Range("A1")
and
all mean the same thing.
The sheet code name is found in the VBE project explorer and it is NOT the one that's in parenthesis. For instance right now under "Microsoft Excel Objects" you have:
Sheet1(Sheet1)
if you change the name to "Properties" it will show:
Sheet1(Properties)
The Sheet1 is the code name and it will not change unless you delete the sheet then add it back in, then it may have a different code name... and, in hindsight, that's what I probably should have used in all references...to use that, you don't have to wrap it with Sheets( ), it's simply:
as shown above.