Passing variables from module to userform

  • Thread starter Thread starter Chris Dunigan
  • Start date Start date
C

Chris Dunigan

Wonder if anyone can help me.

I have an array set up which collects string values. (100 in all)

I'd like to use these values in a userform, but can't work out a way
of getting these values from my code into the userform.

Basically i'd like a form which has the values collected from the
array to be displayed down the left hand side of the form, with a
tick-box to the right of them.

Hope this makes sense to some of you!

Thanks,
Chris
 
Add a listbox to the form

to populate it

For Index = 1 to 100

'''OR
'''For Index = lbound(MyArray,1) to ubound(MyArray,1)

Listbox1.AddItem MyArray(index)
next

set the listbox ListStyle property to frmListStyleOption

Patrick Molloy
Microsoft Excel MVP
 
Chris -

The problem might be more basic (no pun) than Tim or Patrick have
addressed. The beginning user types

UserForm1.Show

And then wonders how to get information into the form and out of it. At
least this is where I once stumbled.

You should first load the form but not show it, then populate the
various controls as Tim and Patrick describe, then show it. When the
user closes the form, make sure the button code hides it, so it's still
in memory and the main procedure can get the information out. Then if
desired, the main sub can unload the form.

....
Load UserForm1
With UserForm1
' Populate the form's controls
.TextBox1.Text = myValue

' Show the form
.Show

' Extract from the form
myNewValue = .TextBox1.Text
End With
Unload UserForm1
....

- Jon
 
Thanks guys,

It was a very simple problem of not declaring a public variable,
therefore the code couldn't pick up the macro values. I was obviously
not all there yesterday!!

Thanks again,
Chris
 
Back
Top