Sub routines in excel

  Desert Andy 14:50 19 Jan 10
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 10

you could write a macro

  VoG II 15:05 19 Jan 10

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 10

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 10

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 10

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

  Desert Andy 18:39 19 Jan 10

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 10

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.

AMD Ryzen release date, specifications and features: Three CPUs from the Ryzen 7 range now…

1995-2015: How technology has changed the world in 20 years

How the painting-like animated sequences in A Monster Calls were created by Glassworks Barcelona

Best iPhone games 2017 | Best iPad games 2017: 162 fantastic iOS games that you need to play right…