UserForm with Combobox

Barbu

New Member
Joined
Mar 7, 2012
Messages
15
Hi, this is my first post, I'm new using VBA.

I'm using a userform with combobox. Combobox options are numbers from 1 to 12, what I need is define the option selected as a public or global variable, because I need to use that number in other macro.

Thanks alot !!!
<!-- / message -->
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Welcome to the Board!

You can set a Public variable in a general module, then set the variable to the ComboBox's value.

E.G. x = Me.ComboBox1.Value

HTH,
 
Upvote 0
Thank you very much Smitty it works !!!

Now I have another question, I want to use this variable "Period" as "X" number of columns in a R1C1 formula, something like this.

Public Period As Integer

Sub CIP_Report()

Range("AA2").FormulaR1C1 = "=SUM(RC[1]:RC[(X)])"

End Sub

but I don't know how can I do it :(

Thanks !!!
 
Upvote 0
Smitty I think I didn't explain it well before, what I have define as variable is "Period" like:

Public Period As Integer

and I tryed:

Range("AA2").FormulaR1C1 = "=SUM(RC[1]:RC[(" & Period & ")])"

But I got an error '1004'

thank you very much for all your help
 
Upvote 0
Lose the Parens before and after Period, so that you only have brackets. Sorry I missed those earlier.
 
Upvote 0

Forum statistics

Threads
1,223,262
Messages
6,171,080
Members
452,377
Latest member
bradfordsam

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