Sal Paradise
Well-known Member
- Joined
- Oct 23, 2006
- Messages
- 2,457
I've been shamelessly using this site as a reference for my diddling with my work spreadsheets for a while now, but I think I have come to an impasse as I try to tackle something well above what my level seems to be. I have several questions, which I will do my best to pose in an easy-to-understand-way, and hope that they aren't excessively simple.
I am trying to create UserForms in VBA for the automatic entry of information. The current userform I'm making is supposed to copy a hidden blank row, insert it to the top of the spreadsheet (with formatting and formulas intact), then create a dialog which gives 4 dropdown menus and a text field which will automatically fill in the proper entries in the new row.
My problem is two-fold:
1) Passing Data between the Dialog Box and the Module in which I will use the data collected and copy it into the proper location.
2) Controlling the Data Box and when it appears
I have a dropdown menu. It has 5 choices in it. Once I select a choice, I want that choice to be copied into a public variable. I want to then take that public variable and enter it into a specific cell in the spreadsheet after the dialogue has closed. I use a button at the bottom to hide the userform after picking the data to be entered.
Here is my code for the UserForm:
(NewEntry is the name of the UserForm, NewJob is the name of the Dropdown Command_box, MakeNewEntry is the name of the command button that's supposed to make the menu go away)
Here is the code for the Module:
Obviously nowhere near completed, because the MsgBox always returns blank values, and I don't know why. Am I making my references wrong? Pointing to the wrong place? Is there a nice and simple tutorial on creating userforms somewhere on the internet that I should take a look at instead?
I can get the dialog box to populate itself, but I can't get the data entered to move out of the userform, or to manipulate the userform with any expertise. Driving me nuts it is, and it seemed so easy before I started.
I am trying to create UserForms in VBA for the automatic entry of information. The current userform I'm making is supposed to copy a hidden blank row, insert it to the top of the spreadsheet (with formatting and formulas intact), then create a dialog which gives 4 dropdown menus and a text field which will automatically fill in the proper entries in the new row.
My problem is two-fold:
1) Passing Data between the Dialog Box and the Module in which I will use the data collected and copy it into the proper location.
2) Controlling the Data Box and when it appears
I have a dropdown menu. It has 5 choices in it. Once I select a choice, I want that choice to be copied into a public variable. I want to then take that public variable and enter it into a specific cell in the spreadsheet after the dialogue has closed. I use a button at the bottom to hide the userform after picking the data to be entered.
Here is my code for the UserForm:
(NewEntry is the name of the UserForm, NewJob is the name of the Dropdown Command_box, MakeNewEntry is the name of the command button that's supposed to make the menu go away)
Code:
Public Sub UserForm_Initialize()
NewEntry.NewJob.AddItem "new" 'ListIndex = 0
NewEntry.NewJob.AddItem "as-is" 'ListIndex = 1
NewEntry.NewJob.AddItem "big" 'ListIndex = 2
NewEntry.NewJob.AddItem "mid" 'ListIndex = 3
NewEntry.NewJob.AddItem "small" 'ListIndex = 4
End Sub
Public Sub NewJob_Change()
Select Case NewJob.Value
Case 0
Module1.VarNewJob = NewEntry.NewJob.Text
Case 1
Module1.VarNewJob = NewEntry.NewJob.Text
Case 2
Module1.VarNewJob = NewEntry.NewJob.Text
Case 3
Module1.VarNewJob = NewEntry.NewJob.Text
Case 4
Module1.VarNewJob = NewEntry.NewJob.Text
End Select
End Sub
Public Sub MakeNewEntry_Click()
NewEntry.Hide
MsgBox (Module1.VarNewRegion)
End Sub
Here is the code for the Module:
Code:
Sub NewRow()
Rows("11:11").Select
Selection.Copy
Selection.Insert Shift:=xlDown
Selection.EntireRow.Hidden = True
NewEntry.Show
MsgBox ("Region: " & VarNewRegion & " Type: " & VarNewType & " Job: " & VarNewJob)
End Sub
Obviously nowhere near completed, because the MsgBox always returns blank values, and I don't know why. Am I making my references wrong? Pointing to the wrong place? Is there a nice and simple tutorial on creating userforms somewhere on the internet that I should take a look at instead?
I can get the dialog box to populate itself, but I can't get the data entered to move out of the userform, or to manipulate the userform with any expertise. Driving me nuts it is, and it seemed so easy before I started.