View Full Version : Same Sub, Different Form


mugwug
10-12-2010, 10:08 PM
Hi, I have the followng code in Excel 2003 VBA.
Both parts reside in 1 Form.
It calls ZZ_FigureCheck and passes to arguments to it.
It works as expected.
I wish to call it from a different form (also from a txt_change)
Is there a way?


Private Sub txtTransAmount_Change()
Call ZZ_FigureCheck(txtTransAmount.Value, txtTransAmount.BackColor)
End Sub


Public Sub ZZ_FigureCheck(Value, BackColour)
'Code
End Sub

smiler44
10-15-2010, 11:27 AM
not sure try removing the word private and or move the
two routines to a module. you might be able to use call txtTransAmount_Change
if you move the routines to a module
if you just remove the word private try using
Call nameofworksheet.txtTransAmount_Change from the other worksheets
smiler44

boblarson
10-15-2010, 11:33 AM
Moved this to the appropriate category (EXCEL).

Also, you can call the functions from another form if you set the subs to PUBLIC instead of PRIVATE. Not sure the exact calling syntax in Excel, but I would go the route that Smiler44 suggested - put them into a module (and set them as PUBLIC) and then you can use them from anywhere.

smiler44
10-15-2010, 12:14 PM
you have 2 replies. just posted this so a reply shows up