Rohan Goel
Rohan Goel

Reputation: 43

Obtaining a value from a userform

I'm trying to get a value from this userform to determine the next step to selecting a material.

Private Sub UserForm_Initialize()

Dim Material(1, 0)
Dim MaterialC As Variant

Material(0, 0) = "Carbon Steel"
Material(1, 0) = "Stainless Steel"

ComboBox1.List = Material
ComboBox1.Value = Material

Worksheets("Sheet2").Range("A1").Value = MaterialC

End Sub

Also would really appreciate it if someone could briefly clarify the difference in a sub and a private sub?

I want to use the choice of the 2 materials to present the user with a set of sizes unique to either choice, so I need to know what they chose.

Also, is there a more efficient way of pasting code than adding 4 spaces before each line of code?

Upvotes: 0

Views: 49

Answers (1)

Lajos Arpad
Lajos Arpad

Reputation: 76426

The difference is the Private keyword. Private is defining the scope of your subroutine, which is that you can only use it inside your Module. Public means that you can call it from outside the Module as well. Since Public is the default scope modifier, the difference between a Sub and a Private Sub is that the Sub will be Publicly usable, while a Private Sub will be kept Private.

For more information read this.

Upvotes: 1

Related Questions