populate dynamic list in dropdown without duplicates items based on sheet name

Hasson

Active Member
Joined
Apr 8, 2021
Messages
406
Office Version
  1. 2016
Platform
  1. Windows
Hi,
I have two sheets contain INVOICE NUMBER in column D .
what I want when write sheet name in J2 cell for OUTCOME sheet then should populate list based on column D in K2 without duplicates items .
SO.xlsm
ABCDEFG
1ITEMDATEBATCHINV NOQTYPRICEBALANCE
2101/01/2023BTS00INV-001201200
3201/01/2023BTS01INV-001501100
4301/01/2023BTS02INV-001502210
5401/01/2023BTS03INV-001601220
6BALANCE01/01/2023INV-0010
7103/01/2023BTS01INV-002701200
8203/01/2023BTS02INV-002801150
9303/01/2023BTS00INV-002601120
10BALANCE03/01/2023INV-0020
11103/01/2023BTS01INV-003801220
12204/01/2023BTS02INV-003801110
13305/01/2023BTS00INV-003801200
14BALANCE06/01/2023INV-0030
15103/02/2023BTS01INV-0042001100
16204/02/2023BTS02INV-0041001200
17305/02/2023BTS00INV-004120120
18BALANCEINV-0040
SH1
Cell Formulas
RangeFormula
G15:G17,G11:G13,G7:G9,G2:G5G2=I2*J2
G6G6=SUM(K2:K5)
G10,G18,G14G10=SUM(K7:K9)


SO.xlsm
ABCDEFG
1ITEMDATEBATCHINV NOQTYPRICEBALANCE
2101/01/2023BTS00STT-0011212220
3201/01/2023BTS01STT-001101220
4301/01/2023BTS02STT-00152440
5401/01/2023BTS03STT-001221450
6BALANCE01/01/2023STT-0010
7103/01/2023BTS01STT-002121300
8203/01/2023BTS02STT-002102300
9303/01/2023BTS00STT-00251500
10BALANCE03/01/2023STT-0020
11103/01/2023BTS01STT-003201300
12204/01/2023BTS02STT-003122300
13305/01/2023BTS00STT-003221500
14BALANCE06/01/2023STT-0030
15103/02/2023BTS01STT-003201300
16204/02/2023BTS02STT-003122300
17305/02/2023BTS00STT-003221500
18BALANCE06/02/2023STT-0030
19103/02/2023BTS01STT-0031341300
20204/02/2023BTS02STT-003242300
21305/02/2023BTS00STT-003341500
22BALANCE06/02/2023STT-0030
REW
Cell Formulas
RangeFormula
G19:G21,G15:G17,G11:G13,G7:G9,G2:G5G2=I2*J2
G6G6=SUM(K2:K5)
G10,G22,G18,G14G10=SUM(K7:K9)

example for SH1 is written in J2 in outcome sheet when select item from K2 should be in K2 like this
PIC1.JPG

every time will add data and the invoices numbers could be 4000 rows for each sheet and the duplicates will be 14000 rows
thanks
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Please try the following on a copy of your workbook. Put all the code below in the sheet code module of the sheet with the validation list.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$J$2" Then
        On Error GoTo Escape
        Application.EnableEvents = False
        Dim sName As String: sName = Target
        If WorksheetExists(sName) Then
            Dim d As Object, arr, i As Long
            Set d = CreateObject("scripting.dictionary")
            arr = Worksheets(sName).Range("D2", Worksheets(sName).Cells(Rows.Count, "D").End(xlUp))
            For i = 1 To UBound(arr, 1)
                d(arr(i, 1)) = 1
            Next i
            With Range("K2")
                .ClearContents
                .Validation.Delete
                .Validation.Add Type:=xlValidateList, Formula1:=Join(d.keys, ",")
                .Select
                .Value = d.keys()(0)
            End With
        Else
            MsgBox "Sheet name " & sName & " does not exist!"
            Target.ClearContents
            Target.Select
        End If
    End If
Continue:
        Application.EnableEvents = True
        Exit Sub
Escape:
        MsgBox "Error " & Err.Number & ": " & Err.Description
        Resume Continue
End Sub
Function WorksheetExists(sName As String) As Boolean
    WorksheetExists = Evaluate("ISREF('" & sName & "'!A1)")
End Function
 
Upvote 0
Solution

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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