combobox values with validation from adjacent cell

kampog

New Member
Joined
Oct 10, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Need help. very new with excel vba. I am populating a combobox from a range but need to check if the adjacent cell is empty or not. The table is being updated dynamically so I need to exclude some values in the list once the table is updated. my code is something like below, so i need to check if C2:C100 has value or empty, if empty put B2 in the combobox list and loop.. thanks in advance guys.


Private Sub List_Prizes()
Dim myrng As Range
Dim data As Range


Set ws = ThisWorkbook.Worksheets("Prizes")
Set myrng = ws.Range("B2:B100")

With Me.cb_PrizeList
.Clear
For Each data In myrng.Cells

If data.Value <> "" Then
.AddItem data.Value
End If
Next data
End With
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
if I understand correctly you want to populate items in combobox1(cb_PrizeList)based on column B if the adjacant cell in columns C is empty, right?
if it's so then change event on user form module (just delete your code and copy mine)
VBA Code:
Private Sub UserForm_Initialize()
Dim myrng As Range
Dim data As Range
Dim lr As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Prizes")
lr = ws.Range("B" & Rows.Count).End(xlUp).Row
Set myrng = ws.Range("B2:B" & lr)
With cb_PrizeList
.Clear
For Each data In myrng.Cells
If data.Offset(, 1) = "" Then
.AddItem data.Value
End If
Next data
End With
End Sub
 
Upvote 0
Solution
if I understand correctly you want to populate items in combobox1(cb_PrizeList)based on column B if the adjacant cell in columns C is empty, right?
if it's so then change event on user form module (just delete your code and copy mine)
VBA Code:
Private Sub UserForm_Initialize()
Dim myrng As Range
Dim data As Range
Dim lr As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Prizes")
lr = ws.Range("B" & Rows.Count).End(xlUp).Row
Set myrng = ws.Range("B2:B" & lr)
With cb_PrizeList
.Clear
For Each data In myrng.Cells
If data.Offset(, 1) = "" Then
.AddItem data.Value
End If
Next data
End With
End Sub
Hello Abdelfattah, thank you very much. That did the trick.

But the issue now is the listindex property of the combobox value is gone. I am using it to reference the row where to update the table, once the save button is click. Duplicate values may occur in the table.
 
Upvote 0
Now I use phone I'm away from my home,sorry
I don't understand what 's your problem?
I would from you explain clearly and if by picture will be better .
Maybe I see later if I have time.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

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