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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
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
how to bring userform from "view code" to main sheet in excel?
 
Upvote 0
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
Well it would help if you gave some more information.:)
 
Upvote 0
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
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,214,545
Messages
6,120,128
Members
448,947
Latest member
test111

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
Back
Top