ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sheet number variable (https://www.excelbanter.com/excel-programming/313852-sheet-number-variable.html)

mikey10[_4_]

Sheet number variable
 

Hi

Quite a simple problem really, but I just cant seem to figure ut out.
have a simple variable in a cell called "ShCount". I would like to writ
a macro that selects the sheet number that relates to the number in cel
'ShCount'. This is the code so far and the second line is not accepted.

Sheet = Range("ShCount")
Sheets(Sheet).Select

Any idea what I am missing?

Many thanks in advance
Mik

--
mikey1
-----------------------------------------------------------------------
mikey10's Profile: http://www.excelforum.com/member.php...fo&userid=1537
View this thread: http://www.excelforum.com/showthread.php?threadid=27008


agarwaldvk[_38_]

Sheet number variable
 

Dear Mike

I presume this is what you are after - not sure though!

If the cell contains a number, then your variable can be made to rea
the value contained in that cell and then activate the workshee
corresponding to the relevant worksheet as follows :-

if the cell address is A1 then

shCount = cells(1,1).value
worksheets(shCount).activate

This should work (after you have put these lines of code in a Sub
presuming that there are at least as many worksheets in your workshee
as the value entered in the referred cell, in this case cell A1

Hopefully, this helps!

If not, please let me know!


Best regards


Deepak Agarwa

--
agarwaldv
-----------------------------------------------------------------------
agarwaldvk's Profile: http://www.excelforum.com/member.php...fo&userid=1134
View this thread: http://www.excelforum.com/showthread.php?threadid=27008


Mart

Sheet number variable
 
When writting code you need to avoid key words such as worksheet or sheet
which are names of objects, properties, events etc.

This can be easily done by using prefixes for your variables to describe the
variable type e.g str for string, d for date, int for integer.

So try

intSheet = Range("ShCount")
Sheets(intSheet).Select

Rgds

M.

"mikey10" wrote:


Hi

Quite a simple problem really, but I just cant seem to figure ut out. I
have a simple variable in a cell called "ShCount". I would like to write
a macro that selects the sheet number that relates to the number in cell
'ShCount'. This is the code so far and the second line is not accepted.

Sheet = Range("ShCount")
Sheets(Sheet).Select

Any idea what I am missing?

Many thanks in advance
Mike


--
mikey10
------------------------------------------------------------------------
mikey10's Profile: http://www.excelforum.com/member.php...o&userid=15378
View this thread: http://www.excelforum.com/showthread...hreadid=270084




All times are GMT +1. The time now is 02:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com