Passing Variables from UserForm Code to Module

JeffGrant

Well-known Member
Joined
Apr 7, 2021
Messages
516
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I know I am doing something exceptionally simple and maybe I am being silly but when I collect variables from the UserForm Code and pass it to a module, the variables loose their value.

This is the code from the OptionButton1_Click
VBA Code:
Option Explicit
Public Horse As String, Ret As Double

Private Sub OptionButton1_Click()
Sheet1.Activate
' Read Variables for when more than one horse is selected
        Horse = Range("T3").Value
        Ret = Range("T2").Value
        Call CopyResults
End Sub


In the VBA Module itself, I also have

VBA Code:
Option Explicit
Public Horse As String, Ret As Double

In the OptionButton1_Click Code, the variable gets assigned properly, because I have checked that with a msgbox, but when I call the CopyResults Routine to wrtite the variables out to another sheet all I get is a blank for the horse name and 0 for the returned value.

What am I missing ?

Cheers
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi
VBA Code:
Public Horse As String, Ret As Double

Delete this one of them
 
Upvote 0
Solution
Hi Mohadin...

Remarkable when I am so close to the trees that i cant see the forest. Thanks
 
Upvote 0
Things happens:)
Thank you for the feedback
Be happy and safe
 
Upvote 0

Forum statistics

Threads
1,214,879
Messages
6,122,065
Members
449,064
Latest member
scottdog129

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