VBA Combo Box populating based on entry in another Combo Box and filtered by another column

skciws

New Member
Joined
Apr 3, 2024
Messages
2
Office Version
  1. 2013
Platform
  1. Windows
We have a table of invoices with 17 columns in.

I have a combo box which populates with the Tenant's company names in and then an invoice number combo box which populates with ONLY the invoices relevant to the tenant selected in the TenantComboBox.

However I need the InvoiceNoComboBox to only show invoices relevant to the selected Tenant WHERE the Invoice isn't already paid. There is a column in the invoice table where the value is "" if it is unpaid or it will have a date in if it is paid.

Code so far for the populating of combo box:

VBA Code:
Private Sub TenantComboBox_Change()

'Populate InvoiceNoComboBox with Invoice Numbers of the Selected Tenant
Dim rngTenant As Range
Dim rngList As Range
Dim rngFilterList As Range
Dim strSelected As String
Dim LastRow As Long

    If TenantComboBox.ListIndex <> "" Then
        
        strSelected = TenantComboBox.Value
        
        LastRow = Worksheets("Outstanding List").Range("E" & Rows.Count).End(xlUp).Row
        
        Set rngList = Worksheets("Outstanding List").Range("E14:E" & LastRow)
        
        Set rngFilterList = Worksheets("Outstanding List").Range("T14:T" & LastRow)
                
        For Each rngTenant In rngList
            
            If rngFilterList.Value <> "" Then
                       
                
            
            If rngTenant.Value = strSelected Then
            
                InvoiceNoComboBox.AddItem rngTenant.Offset(, 2)
                
            End If
                
        Next rngTenant
        
    End If


End Sub

Any help greatly appreciated!!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Realised that the code I posted is my poor attempt at getting where I want to go!
Below is correct code:
VBA Code:
Private Sub TenantComboBox_Change()

'Populate InvoiceNoComboBox with Invoice Numbers of the Selected Tenant
Dim rngTenant As Range
Dim rngList As Range
Dim strSelected As String
Dim LastRow As Long

    If TenantComboBox.ListIndex <> "" Then
        
        strSelected = TenantComboBox.Value
        
        LastRow = Worksheets("Outstanding List").Range("E" & Rows.Count).End(xlUp).Row
        
        Set rngList = Worksheets("Outstanding List").Range("E14:E" & LastRow)
                
        For Each rngTenant In rngList
                      
            If rngTenant.Value = strSelected Then
            
                InvoiceNoComboBox.AddItem rngTenant.Offset(, 2)
                
            End If
                
        Next rngTenant
        
    End If


End Sub
 
Upvote 0

Forum statistics

Threads
1,215,206
Messages
6,123,638
Members
449,109
Latest member
Sebas8956

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