Hello

I have some Listboxes.
If I select an Item on Listbox1, I cant even set the Background of Listbox1 after the end of the code.

So I tried: If Listbox2 is clicked on an item, it shall make listbox1 xy background. This works, but then Listbox1 loose its selection

Can anyone tell me how to set background for a listbox and still not loose the selection? Thank you much for your help

question.png

BTW here the code for Listbox1, and why after code Background cant be set is a mystery:

Private Sub ListBox1_Click()
Dim Txtrng As Range
Dim i As Integer
Dim SelectedItemText As String
Dim mydata As Range
Dim r As Long

ActiveWorkbook.Sheets("Kat1").Range("c1") = ""

Set Txtrng = ActiveWorkbook.Sheets("Kat1").Range("c1")
Txtrng.Value = "X"
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
SelectedItemText = ListBox1.List(i)

End If
Next i

'Recalculates all formulas before proceeding
Application.Calculate
If Not Application.CalculationState = xlDone Then
DoEvents
End If

'Set the value of the cell to the selected item.
Txtrng.Value = SelectedItemText
With Me.ListBox2
.RowSource = ""
Set mydata = Worksheets("Kat1").Range("d2:d20")
.List = mydata.Cells.Value
For r = .ListCount - 1 To 0 Step -1
If .List(r, 0) = "" Then
.RemoveItem r
End If
Next r

End With

Farbelabel.Caption = ""

userform6.ListBox1.BackColor = vbYellow

'Recalculates all formulas before proceeding
Application.Calculate
If Not Application.CalculationState = xlDone Then
DoEvents
End If


End Sub