Hi guys,
Almast a virgin VB coder (~7days) but I have a question on how functions/subs are referenced. I have a button on each of my worksheets which does the same to all of them, but obviously with the different data supplied. I also have a "Total" sheet which sums up the results.
When I update a global variable in the Total sheet I want it to re-do all the calcs on each sheet. I am sure there is a way for a global function or something, but for now: How do I click/activate a button function from another sheet? This is what I ahev so far and only the first line works... - Private Sub total_Click()
-
Worksheets("Sheet1").Activate
-
Worksheets("Sheet1").button1()
-
End Sub
Hope it makes sense, thanks for your help.
4 1983
Hi
Probably the easiest way is to have all your code in a separate code module (not the sheet object module) something like this - Option Explicit
-
-
Sub TotalSheetButtonSub()
-
Sheets("Sheet1").Activate
-
Sheet1ButtonSub
-
Sheets("Sheet2").Activate
-
Sheet2ButtonSub
-
Sheets("Total Sheet").Activate
-
End Sub
-
Sub Sheet1ButtonSub()
-
MsgBox "Sheet1 Procedure"
-
End Sub
-
Sub Sheet2ButtonSub()
-
MsgBox "Sheet2 Procedure"
-
End Sub
You do not say which type of button you are using (Forms or Controls Toolbox Toolbar) but the code in a separate code module is avaiable to both types.
I assume you need to active each sheet because the code in each sub refers to the active sheet? If so, then this is not necessary if your code referes to a reference of the sheet in question. This is paticulary useful if the code is the same for each sheet processed as you can pass the sheet reference as an argument to the Sub and only have one instance of the code to mantain instead of multile copies of the same code.
For instance - Sub TotalSheetButtonSub()
-
SheetButtonSub Sheets("Sheet1")
-
SheetButtonSub Sheets("Sheet2")
-
End Sub
-
Sub SheetButtonSub(ByRef Sht As Worksheet)
-
With Sht
-
MsgBox "This sheet Name is " & .Name
-
End With
-
End Sub
Just some thoughts and ideas, perhaps for the (not too distant!) future?
MTB
Hi
Probably the easiest way is to have all your code in a separate code module (not the sheet object module) something like this - Option Explicit
-
-
Sub TotalSheetButtonSub()
-
Sheets("Sheet1").Activate
-
Sheet1ButtonSub
-
Sheets("Sheet2").Activate
-
Sheet2ButtonSub
-
Sheets("Total Sheet").Activate
-
End Sub
-
Sub Sheet1ButtonSub()
-
MsgBox "Sheet1 Procedure"
-
End Sub
-
Sub Sheet2ButtonSub()
-
MsgBox "Sheet2 Procedure"
-
End Sub
You do not say which type of button you are using (Forms or Controls Toolbox Toolbar) but the code in a separate code module is avaiable to both types.
I assume you need to active each sheet because the code in each sub refers to the active sheet? If so, then this is not necessary if your code referes to a reference of the sheet in question. This is paticulary useful if the code is the same for each sheet processed as you can pass the sheet reference as an argument to the Sub and only have one instance of the code to mantain instead of multile copies of the same code.
For instance - Sub TotalSheetButtonSub()
-
SheetButtonSub Sheets("Sheet1")
-
SheetButtonSub Sheets("Sheet2")
-
End Sub
-
Sub SheetButtonSub(ByRef Sht As Worksheet)
-
With Sht
-
MsgBox "This sheet Name is " & .Name
-
End With
-
End Sub
Just some thoughts and ideas, perhaps for the (not too distant!) future?
MTB
Fanstastic, thanks a lot for your reply. Only one thing: How do I tie a module to a control box button? But the module works exactly how I need it too so already 90% there!
Fanstastic, thanks a lot for your reply. Only one thing: How do I tie a module to a control box button? But the module works exactly how I need it too so already 90% there!
Hi
If you mean a 'Control Toolbox' button, then, based on my previous example, all you do in the 'CommandButton_Click' event is put
'TotalSheetButtonSub' to run all procedures or
'Sheet1ButtonSub' to run the specific sheet procedure.
??
MTB
Hi
If you mean a 'Control Toolbox' button, then, based on my previous example, all you do in the 'CommandButton_Click' event is put
'TotalSheetButtonSub' to run all procedures or
'Sheet1ButtonSub' to run the specific sheet procedure.
??
MTB
Yup, that was it, thanks for al your help Mike, problem solved and lesson learnt!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ilan |
last post by:
Hi all
I need to add data from two Excel sheets (both on the same workbook)
to an existing table in my SQL DB.
The problem is that each sheet holds different fields for the same
record, though...
|
by: Botao |
last post by:
Hi, Every Guru,
I'd like to put a button on a page. When clicking the button, the
table below it gets selected so the user can do Ctrl C to copy the
entire table without using the mouse to...
|
by: PrinStation |
last post by:
I am looking to import data from Excel to Access. The data is set up in one
Excel file, but on 12 (monthly) sheets. After importing the first month/sheet
(which I did successfully), I was looking...
|
by: Osiris Sawiris |
last post by:
I inherited an Inventory control application that updates the stock from the
branches at the end of each day. We receive the stock transactions via
e-mail attachments (Excel Sheets). Those...
|
by: sunilkeswani |
last post by:
I need help with exporting data from 2 access tables, into 2 existing
spreadsheets in a single Excel file.
Currently, I am using this code:
DoCmd.TransferSpreadsheet acExport, 8, "Table1",...
|
by: Hitesh |
last post by:
Hi,
I have three datagrid control on my aspx page and one export to excel
button, i want to export all the 3 datagrids contents in one excel file. how
can i achive that?
--
Thanks
Hitesh
|
by: VK |
last post by:
Hey,
I have some nested datagrids, which I would like to
export to a excel. Exporting is not a problem - however I
would like to export the nested data into different sheets
on the same excel...
|
by: TJ |
last post by:
Hi,
Basically, I want to create excel file on the fly, then force users to
download it
without using automation.
Here is one of ways..
System.IO.StringWriter sw = new...
|
by: stuart79 |
last post by:
I have created a Form for a group of 30 - 40 users.
My users also need to access other excel spread sheets while the form is running. Currently when we try to do this we cannot open other excel...
|
by: dwmaillist |
last post by:
Hello,
I am interested in extracting the information from an excel workbook
with many sheets in it and outputting a csv like text file. Since I
want a single file with all information for all...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |