ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Call a function in some sheets (https://www.excelbanter.com/excel-programming/351791-call-function-some-sheets.html)

henpat

Call a function in some sheets
 
Hello all

I'm creating a code in sheet1, it works fine, but now I need to use the same
code in sheet2 without write again the code.
Also I need to change the name Sheet1 for another name.
In other words, I need a code that can runs in any sheet.

Thanks for your time and sugestions.
henpat
(Excel 2003 SP2)
Call a function in some sheets



Bob Phillips[_6_]

Call a function in some sheets
 
Take the main code out and put in a public sub in a standard code module,
with an argument of sh. Change references to the worksheet to sh.

Then in the worksheet code use

myMacro Me

myMacro would look something like

Sub myMacro (sh As Worksheet)
With sh
...
End With
End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"henpat" wrote in message
...
Hello all

I'm creating a code in sheet1, it works fine, but now I need to use the

same
code in sheet2 without write again the code.
Also I need to change the name Sheet1 for another name.
In other words, I need a code that can runs in any sheet.

Thanks for your time and sugestions.
henpat
(Excel 2003 SP2)
Call a function in some sheets






All times are GMT +1. The time now is 08:50 PM.

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