List Box in Comman Button

raj08536

Active Member
Joined
Aug 16, 2007
Messages
322
Office Version
  1. 365
Platform
  1. Windows
Here my procedure for command button........

Private Sub CommandButton1_Click()
Dim A
Dim B As String
Dim C As String

B = "Enter GM %" & Chr(13) _
& "e.g. 35% or .35"
C = InputBox(B)
' InputBox (ListBox1)
' InputBox (UserForm)
Range("A62").Value = C
A = C

Range("E10").Value = 100
Range("E26").GoalSeek Goal:=A, ChangingCell:=Range("E10")
End Sub

Here is my userform procedure:

Private Sub ListBox1_Click()

End Sub

Private Sub UserForm_Initialize()
With ListBox1
.AddItem "5%"
.AddItem "10%"
End With
End Sub


I want to use listbox in inputbox to limit the option to users.

Need your help urgently...
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Add a Commandbutton to your UserForm and try:

Code:
' Worksheet module
Private Sub CommandButton1_Click()
    UserForm1.Show
    Range("E10").Value = 100
    Range("E26").GoalSeek Goal:=Range("A62").Value, ChangingCell:=Range("E10")
End Sub

' UserForm module

Private Sub UserForm_Initialize()
    With ListBox1
        .AddItem "5%"
        .AddItem "10%"
    End With
End Sub

Private Sub CommandButton1_Click()
    Range("A62").Value = ListBox1.Value
    Unload UserForm1
End Sub
 
Upvote 0

raj08536

Active Member
Joined
Aug 16, 2007
Messages
322
Office Version
  1. 365
Platform
  1. Windows
how to bring userform from "view code" to main sheet in excel?
 
Upvote 0

raj08536

Active Member
Joined
Aug 16, 2007
Messages
322
Office Version
  1. 365
Platform
  1. Windows
everything is working except list box....

Private Sub CommandButton1_Click()
UserForm1.Show
Range("E10").Value = 100
Range("E26").GoalSeek Goal:=Range("A62").Value, ChangingCell:=Range("E10")
End Sub

' UserForm module

Private Sub UserForm_Initialize()
With ListBox1
.AddItem "5%"
.AddItem "10%"
End With
End Sub

Private Sub CommandButton2_Click()
Range("A62").Value = ListBox1.Value
Unload UserForm1
End Sub


Commandbutton1 is in sheets
commandbutton2 is on userform......

I am still not getting listbox populated.
 
Upvote 0

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,358
Office Version
  1. 365
Platform
  1. Windows
Well it would help if you gave some more information.:)
 
Upvote 0

raj08536

Active Member
Joined
Aug 16, 2007
Messages
322
Office Version
  1. 365
Platform
  1. Windows
Now i am getting listbox populated but goal seek function isn't working.....

I am calling userform1 by clicking commandbutton1 (which is in sheet1)

Private Sub CommandButton1_Click()

UserForm1.Show

End Sub

I have listbox1 and commandbutton2 on userform1 and following is the procedure


rivate Sub ListBox1_Click()



End Sub

' UserForm module

Private Sub UserForm_Initialize()

With ListBox1
.AddItem "5%"
.AddItem "10%"
.AddItem "15%"
.AddItem "20%"
.AddItem "25%"
.AddItem "30%"
.AddItem "35%"
.AddItem "40%"

End With


End Sub

Private Sub CommandButton2_Click()

Range("A62").Value = ListBox1.Value
Range("E10").Value = 100
Range("E26").GoalSeek Goal:=Range("A62").Value, ChangingCell:=Range("E10")
Unload UserForm1

End Sub

I am now getting listbox populated but commandbutton2 's procedure not running. Not even A62 amount not changing...

Question:
How do I get listbox value transfer to A62?
 
Upvote 0

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Your code worked for me if UserForm1 contained a ListBox named ListBox1 and a CommandButton named CommandButton2. Check the names of your controls.

Code:
'UserForm module
Private Sub UserForm_Initialize()
    With ListBox1
        .AddItem "5%"
        .AddItem "10%"
        .AddItem "15%"
        .AddItem "20%"
        .AddItem "25%"
        .AddItem "30%"
        .AddItem "35%"
        .AddItem "40%"
    End With
End Sub

Private Sub CommandButton2_Click()
    Range("A62").Value = ListBox1.Value
    Range("E10").Value = 100
    Range("E26").GoalSeek Goal:=Range("A62").Value, ChangingCell:=Range("E10")
    Unload UserForm1
End Sub
 
Upvote 0

Forum statistics

Threads
1,191,123
Messages
5,984,774
Members
439,910
Latest member
Flyingjoblo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top