Data Validation List without duplicates

dsubash

New Member
Joined
Nov 22, 2024
Messages
20
Office Version
  1. 2019
  2. Prefer Not To Say
Platform
  1. Windows
Dear experts,

I have a database in Sheet 1, which contains the following fields
Col. A - List of Branches (Contains Duplicate Entries)
Col. B - List of Products (Contains Duplicate Entries) - certain products are unique to only certain branches while few products are available in all branches.
Col. C - Col. M - other details.

This sheet contains more than 10000 records containing the transactions for a particular month.

I need to prepare a report in Sheet 2 with the Branch and Product as criterias.
In Cell. A2, I have created a dropdown list for branches (after removing duplicates) and used Name Manager to create a Data Validation List.
I need the following in Cell B2 (Sheet 2)
a. A dropdown list of products from Col. B of Sheet 1
b. I need only the products list available against the branch selected in Cell A1 and should not display the products that are not available in the specific branch.
c. Duplicate product names to be removed and only unique names to be available in the dropdown list.
d. Option for autofill product names when one or more characters are typed.
e. Dropdown list should not contain blank entries
f. If possible Product names to be alphabetically displayed.

I tried to use Vlookup and for listing products against each branch in different columns, tried removing duplicates from this list in another column and using name manager for each branch. But since my list of branches and Products are more (20 + branches and 500 + products), I found it difficult to create multiple columns for vlookup and removing duplicates. Also had the problem of blanks in the drop down.

Is there any other options (VBA Code) to get what i want. I am using Office 2019 Professional and hence cannot use formulas avaialble in later versions (Sort / Unique, etc).

I tried viewing many threads in the forum, but was unable to find what i want. Threads available were mostly for higher versions of excel.

Thanks and regards
Subash D
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Here is the corrected macro code. No need of any change in the code for data in the file,. Number of rows of data no worry.. It is taken care of.
VBA Code:
Sub GetBranchProductsList()
Dim A, M, T&, Ta&, K&
Dim Dic1 As Object
Application.ScreenUpdating = False
A = Sheets("Sheet1").Range("A1").CurrentRegion.Offset(1, 0).Resize(, 2)
Set Dic1 = CreateObject("Scripting.dictionary")
With Dic1
For T = 1 To UBound(A, 1) - 1
If .exists(A(T, 1)) Then
    If InStr(1, .Item(A(T, 1)), A(T, 2)) = 0 Then
    .Item(A(T, 1)) = .Item(A(T, 1)) & "_" & A(T, 2)
    End If
Else
.Item(A(T, 1)) = A(T, 2)
End If
Next T
K = .Count
End With

With Sheets("Sheet1").Range("O1")
.CurrentRegion.Offset(1, 0).Clear
.Value = "Branches"
.Offset(1, 0).Resize(K, 1) = WorksheetFunction.Transpose(Dic1.keys)
.Offset(0, 1).Resize(1, K) = Dic1.keys
For Ta = 0 To K - 1
M = Split(Dic1.Item(Dic1.keys()(Ta)), "_")   '
If UBound(M) >= 0 Then .Offset(1, Ta + 1).Resize(UBound(M) + 1, 1) = WorksheetFunction.Transpose(M)
M = ""
Next Ta
End With

Application.ScreenUpdating = True
End Sub
Worksheet event code is for Sheet2 not for Sheet1.
Code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$2" Then Target.Offset(0, 1) = ""
End Sub
Referrer Due Statement - Dec 2025 - Sample - 03-01-2025.xlsm
ABCDEFGHIJ
1Firm_NameRef_Name
2KarurHOME COLLECTION
3
4
5
6Sl. NoFirm_NameRef_NameSID DateSID No.Gross_AmountDiscountPaid_AmountDue_Amount
71KarurHOME COLLECTION04-12-20245599410001000
82KarurHOME COLLECTION04-12-20245599410001000
9         
10         
Sheet2
Cell Formulas
RangeFormula
A7A7=IF(LEN(B7)>0,SUM(A6)+1,"")
B7:B10B7=IF(D7="","",$B$2)
C7:C10C7=IF(D7="","",$C$2)
D7:E10D7=IFERROR(INDEX(Sheet1!C$2:C$4710,AGGREGATE(15,6,ROW(Sheet1!$C$2:$C$4710)/(ISNUMBER(MATCH(Sheet1!$A$2:$A$4710,Sheet2!$B$2,0))*ISNUMBER(MATCH(Sheet1!$B$2:$B$4710,Sheet2!$C$2,0))),ROWS($C$7:$C7))-ROW($B$1)),"")
F7:G10F7=IFERROR(INDEX(Sheet1!G$2:G$4710,AGGREGATE(15,6,ROW(Sheet1!$C$2:$C$4710)/(ISNUMBER(MATCH(Sheet1!$A$2:$A$4710,Sheet2!$B$2,0))*ISNUMBER(MATCH(Sheet1!$B$2:$B$4710,Sheet2!$C$2,0))),ROWS($C$7:$C7))-ROW($B$1)),"")
H7:I10H7=IFERROR(INDEX(Sheet1!J$2:J$4710,AGGREGATE(15,6,ROW(Sheet1!$C$2:$C$4710)/(ISNUMBER(MATCH(Sheet1!$A$2:$A$4710,Sheet2!$B$2,0))*ISNUMBER(MATCH(Sheet1!$B$2:$B$4710,Sheet2!$C$2,0))),ROWS($C$7:$C7))-ROW($B$1)),"")
A8:A10A8=IF(LEN(D8)>0,SUM(A7)+1,"")
Press CTRL+SHIFT+ENTER to enter array formulas.
Cells with Data Validation
CellAllowCriteria
B2List=OFFSET(Sheet1!$O$2,0,0,COUNTA(Sheet1!$O$2:$O$47))
C2List=OFFSET(Sheet1!$O$2,0,MATCH($B2,Sheet1!$P$1:$AF$1,0),COUNTA(INDEX(Sheet1!$P$2:$AF$1000,,MATCH($B2,Sheet1!$P$1:$AF$1,0))))


Sample of result in Sheet1. It extends for more columns actually.
Referrer Due Statement - Dec 2025 - Sample - 03-01-2025.xlsm
OPQRS
1BranchesPondicherrySalemCuddaloreNeyveli
2PondicherryJIPMER HOSPITALSSelfRAMACHANDRA HOSPITALARCHANA HOSPITAL
3SalemHOME COLLECTIONHOME COLLECTION
4Cuddalore
5Neyveli
6Maduranthagam
7Tindivanam
8Chengalpet
9Kallakurichi
10Ilayangudi
11Thiruvarur
12South Street
13Keelakarai
14Chidambaram
15Madurai
16Trichy
17Karur
18Theppakulam
Sheet1
 
Upvote 0
Worksheet event code for Sheet2:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address = "$A$2" Then Target.Offset(0, 1) = ""
Application.EnableEvents = True
End Sub
 
Upvote 0
Worksheet event code for Sheet2:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address = "$A$2" Then Target.Offset(0, 1) = ""
Application.EnableEvents = True
End Sub
Thanks Mr. Murthy,

Will check and revert back shortly

Regards
Subash D
 
Upvote 0
I have modified macro code to incorporate sorting of Product list for each branch.
VBA Code:
Sub GetBranchProductsList()
Dim A, M, T&, Ta&, K&
Dim Dic1 As Object
Application.ScreenUpdating = False
A = Sheets("Sheet 1").Range("A1").CurrentRegion.Offset(1, 0).Resize(, 2)
Set Dic1 = CreateObject("Scripting.dictionary")
With Dic1
For T = 1 To UBound(A, 1) - 1
If .exists(A(T, 1)) Then
.Item(A(T, 1)) = .Item(A(T, 1)) & "," & A(T, 2)
Else
.Item(A(T, 1)) = A(T, 2)
End If
Next T
K = .Count
End With

With Sheets("Sheet 1").Range("K1")
.CurrentRegion.Clear
.Value = "Branches"
.Offset(1, 0).Resize(K, 1) = WorksheetFunction.Transpose(Dic1.keys)
.Offset(0, 1).Resize(1, K) = Dic1.keys
For Ta = 0 To K - 1
M = Split(Dic1.Item(A(Ta + 1, 1)), ",")
If UBound(M) >= 0 Then .Offset(1, Ta + 1).Resize(UBound(M) + 1, 1) = WorksheetFunction.Transpose(M)
    If UBound(M) > 0 Then
    .Offset(1, Ta + 1).Resize(UBound(M) + 1, 1).Sort Key1:=.Offset(1, Ta + 1), Order1:=xlAscending, Header:=xlNo
    End If
M = ""
Next Ta
End With

Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,225,169
Messages
6,183,318
Members
453,155
Latest member
joncaxddd

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