This is my first request on this forum.
I cannot find this seemingly simple answer.
I have a multiselect listbox (serlib) and textbox( fnbx) on a userform.
The Commandbutton has vba that search the reference number(which is in the textbox) down column A, and if found, populates the Listbox with the appropriate results.
The listbox has 9 columns.
I need to do the following:
After making a selection(s) in the listbox, and with another Commandbutton, the word "paid" needs to be written into the last column of the found row on the sheet.
I was trying to have the reference number on the sheet selected, and write "Paid" to activecell.offset(0,9), but it does not work.
I also tried the following:
If .Selected(cntr) Then serlib.List(0, 9) = "PAID"
End If
But that only changes the Listbox content and not the needed cell.
Please help.
Here is my code on the find portion:
Private Sub CommandButton2_Click()
With Worksheets(1).Range("A1:A2000")
Set c = .Find(What:=fnbx, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=True)
If Not c Is Nothing Then
firstaddress = c.Address
Do
serlib.AddItem c.Value
'.List c.Offset(0, 1)
serlib.List(serlib.ListCount - 1, 1) = c.Offset(0, 1)
serlib.List(serlib.ListCount - 1, 2) = c.Offset(0, 2)
serlib.List(serlib.ListCount - 1, 3) = c.Offset(0, 3)
serlib.List(serlib.ListCount - 1, 4) = c.Offset(0, 4)
serlib.List(serlib.ListCount - 1, 5) = c.Offset(0, 5)
serlib.List(serlib.ListCount - 1, 6) = c.Offset(0, 6)
serlib.List(serlib.ListCount - 1, 7) = c.Offset(0, 7)
serlib.List(serlib.ListCount - 1, 8) = c.Offset(0, 8)
serlib.List(serlib.ListCount - 1, 9) = c.Offset(0, 9)
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstaddress
End If
End With
End Sub
Here is something I thought would work, but I cannot complete the code:
Private Sub CommandButton3_Click()
Dim i As Long, x
With Me.serlib
For i = 0 To .ListCount - 1
If .Selected(i) Then
'this is wrong!!!
Selected(i).List(0, 9) = "PAID"
Exit Sub
End If
Next
End With
End Sub
I cannot find this seemingly simple answer.
I have a multiselect listbox (serlib) and textbox( fnbx) on a userform.
The Commandbutton has vba that search the reference number(which is in the textbox) down column A, and if found, populates the Listbox with the appropriate results.
The listbox has 9 columns.
I need to do the following:
After making a selection(s) in the listbox, and with another Commandbutton, the word "paid" needs to be written into the last column of the found row on the sheet.
I was trying to have the reference number on the sheet selected, and write "Paid" to activecell.offset(0,9), but it does not work.
I also tried the following:
If .Selected(cntr) Then serlib.List(0, 9) = "PAID"
End If
But that only changes the Listbox content and not the needed cell.
Please help.
Here is my code on the find portion:
Private Sub CommandButton2_Click()
With Worksheets(1).Range("A1:A2000")
Set c = .Find(What:=fnbx, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=True)
If Not c Is Nothing Then
firstaddress = c.Address
Do
serlib.AddItem c.Value
'.List c.Offset(0, 1)
serlib.List(serlib.ListCount - 1, 1) = c.Offset(0, 1)
serlib.List(serlib.ListCount - 1, 2) = c.Offset(0, 2)
serlib.List(serlib.ListCount - 1, 3) = c.Offset(0, 3)
serlib.List(serlib.ListCount - 1, 4) = c.Offset(0, 4)
serlib.List(serlib.ListCount - 1, 5) = c.Offset(0, 5)
serlib.List(serlib.ListCount - 1, 6) = c.Offset(0, 6)
serlib.List(serlib.ListCount - 1, 7) = c.Offset(0, 7)
serlib.List(serlib.ListCount - 1, 8) = c.Offset(0, 8)
serlib.List(serlib.ListCount - 1, 9) = c.Offset(0, 9)
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstaddress
End If
End With
End Sub
Here is something I thought would work, but I cannot complete the code:
Private Sub CommandButton3_Click()
Dim i As Long, x
With Me.serlib
For i = 0 To .ListCount - 1
If .Selected(i) Then
'this is wrong!!!
Selected(i).List(0, 9) = "PAID"
Exit Sub
End If
Next
End With
End Sub