Update cell value with combo box selection where rows match multiselect listbox selections

accrualguy

New Member
Joined
Jul 2, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Web
Greetings! I've really hit a wall on this one and hoping someone has a solution.

I have a user form named "MatchForm". There is a multi-select listbox [lstGL] on the form that has nine (9) columns. When a user selects one or more rows in the listbox, along with a value from a combobox [cboStatus], the "Match Entries" command button on the form should update the cell value in column N on worksheet "GL Recon" where the value in column A (on worksheet "GL Recon") is equal to the first column's value of the selected item(s) in the listbox.

Being a multi-select listbox, I realize there will need to be a loop but I honestly don't know where to start.

Thanks in advance for your time and assistance!!!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi and welcome to MrExcel.

Try this:

VBA Code:
Private Sub CommandButton1_Click()
  Dim i As Long
  Dim f As Range
  Dim sh As Worksheet
  
  If cboStatus.ListIndex = -1 Then
    MsgBox "Select status"
    cboStatus.SetFocus
    Exit Sub
  End If
  
  'update sheet
  Set sh = Sheets("GL Recon")
  For i = 1 To lstGL.ListCount - 1
    If lstGL.Selected(i) Then
      Set f = sh.Range("A:A").Find(lstGL.List(i, 0), , xlValues, xlWhole)
      If Not f Is Nothing Then
        sh.Range("N" & f.Row).Value = cboStatus.Value
      End If
      'unselect row in the listbox
      lstGL.Selected(i) = False
    End If
  Next i
  
  'clear combo
  cboStatus.Value = ""
  
  MsgBox "updated"
End Sub
 
Upvote 0
With one minor tweak, that worked for me! I ended up changing
VBA Code:
 For I = 0
for the sheet update, otherwise it would only update one of the selections.

Tremendous thanks, Dante!
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,752
Members
448,989
Latest member
mariah3

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