• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Data from User Forms

Shaun

Member
Hi Everyone


I am preparing a user form which incorporates date, time and then selections from drop down lists. The first list is 1 to 3, at this point I would like the second list to be generated from the first, the code:

[pre]
Code:
Private Sub UserForm_Activate()
FormDate = Format(Now(), "DD MMMM YYYY")
FormTime = Format(Now(), "H:MM:SS am/pm")

With Number
.AddItem "1"
.AddItem "2"
.AddItem "3"
End With

With Number2
If Number.Value = "1" Then
.AddItem "4"
Else
If Number = "2" Then
.AddItem "5"
.AddItem "6"
.AddItem "7"
.AddItem "8"
.AddItem "9"
.AddItem "10"
Else
If Number = "3" Then
.AddItem "11"
.AddItem "12"
.AddItem "13"
.AddItem "14"
.AddItem "15"
Else
End If
End If
End If
End With
End Sub
[/pre]

The problem I have is that I cannot work out is how to generate Number2 list based on Number list. Just thinking as I type, I probably need to have a second user form as it would not be possible to generate list Number2 "on the fly" using this method.


The other issue I am having is that I don't know how to get the data from the form into the spread sheet, are there any good tutorials? I haven't been able to find any.


Cheers


Shaun
 
Hi, Shaun!


Give a look at this file:

https://dl.dropbox.com/u/60558749/Data%20from%20User%20Forms%20%28for%20Shaun%20at%20chandoo.org%29.xlsm


It has an user form with two list controls, I think it behaves as you wanted. This is your updated code:

-----

[pre]
Code:
Option Explicit

Private Sub Number_Change()
' constants
' declarations
' start
' process
'  second list
With Number2
.Clear
If Number.Value = "1" Then
.AddItem "4"
Else
If Number = "2" Then
.AddItem "5"
.AddItem "6"
.AddItem "7"
.AddItem "8"
.AddItem "9"
.AddItem "10"
Else
If Number = "3" Then
.AddItem "11"
.AddItem "12"
.AddItem "13"
.AddItem "14"
.AddItem "15"
Else
End If
End If
End If
End With
End Sub

Private Sub UserForm_Activate()
' constants
' declarations
Dim FormDate As String, FormTime As String
' start
FormDate = Format(Now(), "DD MMMM YYYY")
FormTime = Format(Now(), "H:MM:SS am/pm")
' process
'  first list
With Number
.AddItem "1"
.AddItem "2"
.AddItem "3"
End With
'  second list
With Number2
If Number.Value = "1" Then
.AddItem "4"
Else
If Number = "2" Then
.AddItem "5"
.AddItem "6"
.AddItem "7"
.AddItem "8"
.AddItem "9"
.AddItem "10"
Else
If Number = "3" Then
.AddItem "11"
.AddItem "12"
.AddItem "13"
.AddItem "14"
.AddItem "15"
Else
End If
End If
End If
End With
' end
End Sub
[/pre]
-----


Just advise if any issue.


Regards!


PS: Please always use Option Explicit statement, it's safe and avoid unwanted typo errors.
 
Hi SirJB7


The file you have uploaded behaves exactly as I had tried to achieve.


Thank you very much.


Cheers


Shaun
 
Hi, Shaun!

Glad you solved it. Thanks for your feedback and for your kind words too. And welcome back whenever needed or wanted.

Regards!
 
Back
Top