#1   Report Post  
Michael
 
Posts: n/a
Default Active sheet

Hi.

I have 1 workbook with 13 different worksheets. My question is:

I have a lot of vb code that is the same for each worksheet. ex:

When woorksheet(2) is chosen i want that to be the active worksheet, and
insead of this code:

MaterialRow = Worksheets(2).Range("Material").Row

I would love to have a code instead of Worksheets(2), if i have it like this
i have to change to worksheet(3) in the formula when worksheet(3) is chosen
etc etc.

And a code change the active worksheet.

Please help!!
--
Nil Satis Nisi Optimum
  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

Have you tried

MaterialRow = Activesheet.Range("Material").Row


--
HTH

Bob Phillips

"Michael" wrote in message
...
Hi.

I have 1 workbook with 13 different worksheets. My question is:

I have a lot of vb code that is the same for each worksheet. ex:

When woorksheet(2) is chosen i want that to be the active worksheet, and
insead of this code:

MaterialRow = Worksheets(2).Range("Material").Row

I would love to have a code instead of Worksheets(2), if i have it like

this
i have to change to worksheet(3) in the formula when worksheet(3) is

chosen
etc etc.

And a code change the active worksheet.

Please help!!
--
Nil Satis Nisi Optimum



  #3   Report Post  
Michael
 
Posts: n/a
Default

Well Bob.

I want the sheet(2) to be active if that is chosen, something like this.

Dim wks as worksheet ' to tell that wks is the open sheet no mather the name

wks=worksheet(2) 'In sheet(2) when its active, later i can just change
that code to wks=worksheet(3) etc, if i dont do that i have to change 100 of
lines in each worksheet

Then i can change the formula:

MaterialRow = Worksheets(2).Range("Material").Row

to

MaterialRow = wks.Range("Material").Row

Then the formula should work for all the sheets when the sheet is active. Is
it possible?



--
Nil Satis Nisi Optimum


"Bob Phillips" wrote:

Have you tried

MaterialRow = Activesheet.Range("Material").Row


--
HTH

Bob Phillips

"Michael" wrote in message
...
Hi.

I have 1 workbook with 13 different worksheets. My question is:

I have a lot of vb code that is the same for each worksheet. ex:

When woorksheet(2) is chosen i want that to be the active worksheet, and
insead of this code:

MaterialRow = Worksheets(2).Range("Material").Row

I would love to have a code instead of Worksheets(2), if i have it like

this
i have to change to worksheet(3) in the formula when worksheet(3) is

chosen
etc etc.

And a code change the active worksheet.

Please help!!
--
Nil Satis Nisi Optimum




  #4   Report Post  
Michael
 
Posts: n/a
Default

Thanks Bob.

i didnt understand at first, know i checked and your formula works perfect.

Thanks again :-)
--
Nil Satis Nisi Optimum


"Bob Phillips" wrote:

Have you tried

MaterialRow = Activesheet.Range("Material").Row


--
HTH

Bob Phillips

"Michael" wrote in message
...
Hi.

I have 1 workbook with 13 different worksheets. My question is:

I have a lot of vb code that is the same for each worksheet. ex:

When woorksheet(2) is chosen i want that to be the active worksheet, and
insead of this code:

MaterialRow = Worksheets(2).Range("Material").Row

I would love to have a code instead of Worksheets(2), if i have it like

this
i have to change to worksheet(3) in the formula when worksheet(3) is

chosen
etc etc.

And a code change the active worksheet.

Please help!!
--
Nil Satis Nisi Optimum




  #5   Report Post  
Bob Phillips
 
Posts: n/a
Default

Phew, thank goodness. I just read your follow-up and was thinking that my
previous answer still applied <G

Bob

"Michael" wrote in message
...
Thanks Bob.

i didnt understand at first, know i checked and your formula works

perfect.

Thanks again :-)
--
Nil Satis Nisi Optimum






  #6   Report Post  
Michael
 
Posts: n/a
Default

Thank you again:-)
--
Nil Satis Nisi Optimum


"Bob Phillips" wrote:

Phew, thank goodness. I just read your follow-up and was thinking that my
previous answer still applied <G

Bob

"Michael" wrote in message
...
Thanks Bob.

i didnt understand at first, know i checked and your formula works

perfect.

Thanks again :-)
--
Nil Satis Nisi Optimum





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
data from one sheet to several in sequential order! firecord New Users to Excel 6 June 22nd 05 05:10 PM
Using the Active cell in one sheet for another sheet JOHNNY_E Excel Discussion (Misc queries) 0 May 4th 05 06:19 AM
How to change macro so it performs actions on ACTIVE sheet? Tom9283 Excel Discussion (Misc queries) 6 April 15th 05 07:32 AM
linking multiple sheets to a summary sheet greg g Excel Discussion (Misc queries) 1 December 16th 04 07:43 AM
Naming & renaming a sheet tab Cgbilliar Excel Worksheet Functions 1 November 7th 04 05:57 PM


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