VBA Private Sub for all sheets

BrainDiseasee

New Member
Joined
Aug 30, 2023
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a private sub i am using in a template style sheet, goal is to be able to essentially duplicate this "Template" worksheet and apply unique title and information to the new sheet name. I have all of that down.
Here is my problem i have two TextBox's from the developer tab each one has a private sub in the sheet to display the data entered into a cell on another sheet called "Master_Data". Here is the code, i am needing a solution on how to have this apply to each sheet or if i can do something like "If ws.Name <>" to limit what sheets dont need this. Anyway below is the code and help would awesome, thanks!!!!

Option Explicit

Private Sub TextBox1_Change()
Sheets("Master_Data").Range("W9").Value = TextBox1.Value
End Sub

Private Sub TextBox2_Change()
Sheets("Master_Data").Range("W10").Value = TextBox2.Value
End Sub
 
My suggestion is rather than having this code and textbox controls on each worksheet. Have your code and controls functioning at the Workbook level.

I have a test Workbooks where I pop-up the following UserForm when you are on the Master_Data sheet or any other applicable sheet.
When the form is activated for Master_Data, the ComboBox (Size selection) and Go Live Date text box are disabled.
If on another applicable sheet the Start By Date is disabled and the ComboBox and Go Live Date text box are enabled.

Update button, likewise, will be a function of which worksheet is active.
If on a worksheet other than "Master_Data" the Update button will save the values of the first 2 controls to Master Data Cells W9 and W10
if on the "Master_Data" sheet the value of the 3rd control will be saved to the active sheet (Cell? TBD).

The code is all in the form code for the controls.

1693487358869.png
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Thanks for your help, i was thinking about this last night except i'm not super familiar with building the user forms.
 
Upvote 0
Is it possible to share a copy of this file with me so i can try to replicate the example?
 
Upvote 0
Is it possible to share a copy of this file with me so i can try to replicate the example?
Here is a link to my test code. Please keep in mind this is not by any means a complete and working Workbook.
I it primarily implements a non-modal dialog box with 5 controls on it (A ComboBox, 2 TextBoxes (and a couple of buttons not fully implemented).
It is just to give you an idea how you might go about implementing your project.
I hope this helps.

BrainDisease.XLSM
 
Upvote 0
Thanks, i can see what this is doing and after some tweaking i can get this functional. I really appreciate all the help. Thank you again!
 
Upvote 0

Forum statistics

Threads
1,215,200
Messages
6,123,612
Members
449,109
Latest member
Sebas8956

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top