Userform with input numerical number with listbox

jocker_boy

Board Regular
Joined
Feb 5, 2015
Messages
83
Hi,

I found this code:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    Application.EnableEvents = False
    On Error GoTo exitHandler
 
    If Target.Column = 10 Then
      gCountryListArr = Sheets("RESOURCES").Range("Table2[COD]").Value
      gCellCurrVal = Target.Value
      UserForm1.Show 'Pop up the form
      Target.Value = gCellCurrVal
    End If

exitHandler:
    Application.EnableEvents = True
End Sub

and:

Code:
Private Sub CommandButton1_Click()
  UserForm1.Hide 'Pop up the form
End Sub
Private Sub CommandButton2_Click()
    For ii = 0 To ListBox1.ListCount - 1
        Me.ListBox1.Selected(ii) = False
    Next ii
End Sub
Private Sub CommandButton3_Click()
    For ii = 0 To ListBox1.ListCount - 1
        Me.ListBox1.Selected(ii) = True
    Next ii
End Sub

Private Sub CommandButton4_Click()
    gCellCurrVal = ""
    For ii = 0 To ListBox1.ListCount - 1
      If Me.ListBox1.Selected(ii) = True Then
        If gCellCurrVal = "" Then
          gCellCurrVal = Me.ListBox1.List(ii)
        Else
          gCellCurrVal = gCellCurrVal & ";" & Me.ListBox1.List(ii)
        End If
      End If
    Next ii
    UserForm1.Hide
End Sub

Private Sub UserForm_Activate()
On Error Resume Next
'On each activation, clear the whole,
'then add every country list element as blank
Me.ListBox1.Clear
For Each element In gCountryListArr
  Me.ListBox1.AddItem element
Next element
UserForm_initialize
End Sub


Private Sub UserForm_initialize()
  For Each element In Split(gCellCurrVal, ";")
    For ii = 0 To ListBox1.ListCount - 1
      If element = Me.ListBox1.List(ii) Then
        Me.ListBox1.Selected(ii) = True
      End If
    Next ii
  Next element
End Sub

Sorry for not posting a image, but in my companies i can't find any site for hosting images that aren't block.

But the userform have 4 buttons: "Cancel"; "Clear"; "ALL"; "Ok".

This works perfect, because i need to select multiples strings to input in one cell.
However, i would like to input a diferent numerical number behind each string.
For example, if i have my strings:

ABC
DE
FGHI
JKL
MNOP
RST


I would like to select a cell, open a userform and have the possibility to write:

0,25 and pick ABC
1,00 and pick FGHI
0,75 and pick JKL

To input the cell this result:

"0,25ABC;1,00FGHI;0,75JKL"

Is this possible?

Many thanks in advance.
Gonçalo
 
I do not understand what do you need?

Make the listbox wider so you can see the data

Add this line in your Activate Event:

Code:
Private Sub UserForm_Activate()
On Error Resume Next
'On each activation, clear the whole,
'then add every country list element as blank
Me.ListBox1.Clear
For Each element In gCountryListArr
  Me.ListBox1.AddItem element
Next element

[B][COLOR=#0000ff]Listbox1.ColumnCount = 2[/COLOR][/B]


UserForm_initialize
End Sub
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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