Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88066

Using a textbox in a userform to add information to 2 column i listbox in the same userform, Excel VBA

$
0
0

I'm adding information from a textbox (tbxBladnr) to a multiselect Listbox (lbxSektioner) second column, that are placed on the same userform. I can't get this to work. One thing is

If Not lbxSektioner.List(iCount, 1) = "" Then

I can't get the part lbxSektioner.List to function the fault I get is that it cant access the List argument. Here is the full code.

Option Explicit

Private Sub lbxSektioner_Click()

End Sub

'Starta formuläret
Private Sub UserForm_Initialize()

Call FillListbox

End Sub

'Fyll listboxen från rätt i filen
Sub FillListbox()
Dim arrSektion As Variant
    arrSektion = Range("B1:B"& Cells(Rows.Count, 2).End(xlUp).Row).Value
    lbxSektioner.List = arrSektion
End Sub

Private Sub cmbLaggtill_Click()

Dim iCount As Integer
Dim strString As String
For iCount = 0 To lbxSektioner.ListCount - 1
   If (lbxSektioner.Selected(iCount) = True) Then
        If Not lbxSektioner.List(iCount, 1) = "" Then
         strString = lbxSektioner.List(iCount, 1) & ", "& tbxBladnr.Value
        Else
        strString = tbxBladnr.Value
        End If
      lbxSektioner.List(iCount, 1) = lbxSektioner.List(iCount, 1) & ", "& strString
   End If
Next iCount

End Sub 

Viewing all articles
Browse latest Browse all 88066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>