LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Calling a subroutine - how to?

[Excel 2003]

I use code with command buttons in userforms. At present I have the
following code

Private Sub cmdShowSheet1Items_Click()
WhichSheet = "Sheet 1"

Dim ws As Worksheet
Set ws = Worksheets("Sheet 1")

'Sheet Details
Me.txt1.Value = ws.Range("A1").Value
Me.txt2.Value = ws.Range("B32").Value
Me.txt3.Value = ws.Range("A15").Text
etc etc

End Sub

This works great at populating text boxes with information from the sheet.

However, I have 10 sheets with different data stored in the same cells (in
the code above), so at present I use 10 buttons each repeating the above code
each time but with a different sheet specified as the source.

Although this works fine, It is very cumbersome (I have hundreds of cells
that I call into the userform).

Alternatively I would like to have the "get sheet details" in a separate sub
routine (since these cell references never change across the sheets), called
up from the button click

I have tried separating this part of the code, but I am not sure how to
handle such a sub routine. Ideally I need something like :

Private Sub cmdShowSheet1Items_Click()


Dim ws As Worksheet
Set ws = Worksheets("Sheet 1")

Call GetSheetDetails???

End Sub


And then somewhere else I have

Subroutine GetSheetData?

Me.txt1.Value = ws.Range("A1").Value
Me.txt2.Value = ws.Range("B32").Value
Me.txt3.Value = ws.Range("A15").Text
etc etc
Then return to original subroutine
End Sub

Can anyone help as this would streamline my code immensely

Thanks,

Roger
 
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
Calling a VBA add in from a macro subroutine [email protected] Excel Programming 1 April 6th 07 10:09 PM
Calling a subroutine in a loop Jeff@DE Excel Programming 1 January 9th 06 09:56 AM
calling a subroutine outside a spreadsheet dino Excel Programming 5 June 11th 04 06:14 PM
Function Calling Subroutine Curare Excel Programming 1 February 24th 04 07:11 PM
Calling the Solver via a subroutine James[_8_] Excel Programming 1 July 10th 03 01:08 AM


All times are GMT +1. The time now is 06:38 AM.

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"