Avatar of kerrybenno
kerrybenno
 asked on

Spin Button and Textboxes Excel VBA

I have a userform in Excel with 10 textboxes that require dates, the date in each textbox is currently controlled by its own spin button.  Is there a way to have one piece of code that when the spin button is pressed, it knows what textbox this relates to.
I thought by grouping together the spin button and relevant textbox that I may be able to do it, but i've not figured a way yet.
Microsoft OfficeMicrosoft Excel

Avatar of undefined
Last Comment
Rory Archibald

8/22/2022 - Mon
CheetoBandito

Each spin button will have it's own _Change() event.  If you edit that event and insert code to reference the appropriate text box, they will effectively be 'linked'.

Alternatively you use the Me.Name property to get the name of the spin button.  If you name all your textboxs the same base name with a different number at the end, and then do the same for the spinbuttons.  You can do a Right(Me.Name, 1) to get the number of the spin button and then right a function passing that number as an argument, and then update the corresponding textbox based on the number.

Depending on how big of a form this is, it might not be worth it to write this function...you might be better off just copying-pasting the block and changing the appropriate values.
ASKER CERTIFIED SOLUTION
Rory Archibald

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck