Sub routines in excel

  Desert Andy 14:50 19 Jan 2010
Locked

I'm planning to write a large program in Excel. I wish to use a sub-routine that will be used in many of the different worksheets. Is there any way of accessing the same sub routine from many different worksheets, thus saving a lot of extra code?

Thanks

  howard64 15:00 19 Jan 2010

you could write a macro

  VoG II 15:05 19 Jan 2010

Not sure what you mean - a Subroutine should be accessible from any worksheet. Or do you mean work*books* ?

If the latter click here

  Desert Andy 15:48 19 Jan 2010

Sorry, didn't make myself completely clear. I would like to write a subroutine in say Sheet1, and then access that subroutine from Sheet2. Is that possible?

Thanks

  OTT_B 16:23 19 Jan 2010

Reading your post, i get the impression you are talking about creating a worksheet formula (i.e. a formula in a cell). You then want to use that formula in another place in the workbook without having to retype it.

Is that correct?

  VoG II 16:30 19 Jan 2010

Subroutines should go in general modules, not worksheet code modules.

  Desert Andy 18:39 19 Jan 2010

Thank you. How do I set up say a subroutine, to ask a persons name using a button in sheet 1 and sheet2. How do a write/label a subroutine in a generel module to access from any worksheet. Many thanks for your help.

  VoG II 18:46 19 Jan 2010

For the button code on both sheets you could use

Private Sub CommandButton1_Click()
Call EnterName
End Sub


Then in a regular module something like


Sub EnterName()
Range("A1").Value = InputBox("Enter your name")
End Sub

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

Galaxy Note 8 vs iPhone X

5 best 3D model websites

iPhone 8 vs iPhone X

WhatsApp : comment lire vos messages sans que l’expéditeur le sache