0

I have created a UserForms with a comboBox (dropdown). And i have also written sub in a module.

I want to call the userforms in the one the steps of the sub, like a Inputbox.

The userforms

enter image description here

I have written the a Public Sub UserForm_Initialize() in userforms code

Public Sub UserForm_Initialize()
Dim t

UserForm.Show
t = ComboBox1.Value
End Sub

My code in the module :

Sub Ingestion()
Dim x, z
Dim rRange

Sheets("Time Log").Select
x = Range("H300").End(xlUp).Row

If Range("A" & x).Value <> "" Then
    z = InputBox("Please confirm the Task type")
    Range("B" & x) = z

End If


End Sub

Now I want to change the Input box to the combobox.

but if i call this in the module, it throws an Error :

Sub Test()
Call UserForm_Initialize

End Sub

Sub or Function Not Defined 

Basically, i am trying to create a Inputbox with drop down options.

Thomas G
  • 9,886
  • 7
  • 28
  • 41
Sweta Garg
  • 43
  • 5
  • You need to share your entire code, and on what line the code breaks. Can't help you now. Read on [how to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Tim Stack Apr 23 '19 at 07:28
  • Does this help ? let me know if anything else required from my end. Thank you for helping out. :) – Sweta Garg Apr 23 '19 at 07:46

1 Answers1

0

A UserForm_Initialize event gets executed as soon as, surprise, the userform is initialized. So, trying to show the UF when it's already being opened is illogical. Next to that you'd have to refer to the correct UF name, in this case that would result in TaskList.Show.

You open the UF outside of the UF's code module. For example

Sub openUF()

TaskList.Show

End Sub

Then you can execute code inside the UF's module. These are usually bound to objects on the UF, e.g.:

Sub CommandButton_Click() 'in case the UF has a command button and a combobox

MsgBox "You picked '" & Me.ComboBox1.Value & "'.", vbInformation, "Help"

End Sub
Tim Stack
  • 3,209
  • 3
  • 18
  • 39
  • Thank you. This works in calling the box. can you also help me add the value selected in a selected cell. – Sweta Garg Apr 23 '19 at 10:40
  • If you need help populating a combobox, read [this](https://stackoverflow.com/questions/29565846/how-to-populate-a-combobox) or look around on SO for other threads – Tim Stack Apr 23 '19 at 10:52
  • @SwetaGarg If my answer helped you, please don't forget to accept the answer :) – Tim Stack Apr 25 '19 at 06:38