Populating Combobox from multiple conditional ranges on multiple sheets

Kaarrma

New Member
Joined
Jun 8, 2018
Messages
4
Hi All,

I have a combobox on a userform that i need to add values from a fixed range (With criteria), but i need it to do this across 4 sheets

The Sheets are "WRS P1", "WRS P2", "WRS P3" and "WRS P4"
Column A has a range of Dates (A8:A32) (This range has a formula in all cells within range, but only some may actually be populated with a value)
I need these dates added to the Combobox when the cell in column E is empty
The dates in column A will fill the above range in WRS P1 first, then once the range is full, it will flow to WRS P2 in the same range, then to WRS P3 and so on

I need some code to cycle through the range in the first sheet (WRS P1),
Once the code reaches an empty cell in column A (Within the range) then the code can stop

I have code to do this on 1 sheet, but i cannot seem to get it to continue looking on the next sheet

This is the code i currently have:

Any assitance would be greatly appreciated!

VBA Code:
Dim rngEmpD As Range
Dim rngListD As Range
Dim strSelectedD As String
Dim LastRowD As Long

            strSelectedD = ""
          
            LastRowD = Worksheets("WRS P1").Range("A8:A32").Find("", , xlValues, , , xlNext, , , False).Row
 
           Set rngListD = Worksheets("WRS P1").Range("E8:E" & LastRowD - 1)
 
           For Each rngEmpD In rngListD
 
                 If rngEmpD.Value = strSelectedD Then
 
                      Me.ComboBox1.AddItem rngEmpD.Offset(, -3)
                    
 
                 End If
 
           Next rngEmpD
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try this:

VBA Code:
Private Sub UserForm_Activate()
  Dim sh As Variant
  Dim c As Range
  
  For Each sh In Array("WRS P1", "WRS P2", "WRS P3", "WRS P4")
    For Each c In Sheets(sh).Range("A8:A32")
      If Sheets(sh).Range("E" & c.Row).Value = "" Then
        ComboBox1.AddItem c.Value
      End If
    Next
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

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