pull unique values from a column as they appear

jonattempt_cell

New Member
Joined
Mar 5, 2015
Messages
26
I am trying to write a vba function, sub or to call a sub / function that would pull unique values in a column's range to another, larger column on the same or different worksheet. I want to pull the unique values as they appear because they may disappear.

Imagine for example people enter a restaurant and orders arrive to the chef but are thrown i nthe bin once they leave. Each order has a unique receipt and I'd like that receipt to be recorded and entered in the last empty row of the destination column.

For example column B3:B30 contains the receipt id for customers as they arrive. I'd need column C:C to record to the last empty cell the unique orders as they arrive. As people leave the restaurant column B3:B30 will fill to the top so the code will need to adjust and search the whole of B3:B30

so far I have
Code:
<code>Sub ertdfgcvb()
Dim rng As Range
Dim Unique As Boolean

For Each rng In Worksheets("Sheet1").Range("B1:B30") 'for each cell in your B1 to B30 range, sheet1
    Unique = True 'we'll assume it's unique
    Lastunique = Worksheets("Sheet2").Range("B:B").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For i = 1 To Lastunique 'for each cell in the unique ID cache
        If rng.Value = Worksheets("Sheet2").Cells(i, 2).Value Then 'we check if it is equal
            Unique = False 'if yes, it is not unique
        End If
    Next
    If Unique Then Worksheets("Sheet2").Cells(Lastunique + 1, 2) = rng 'adds if it is unique
Next
End Sub


</code>
<code><code>
Code:
Private Sub WorkSheet_Change(ByVal Target As Range)
Call ertdfgcvb
End Sub
</code>


Code:
Private Sub WorkSheet_Change(ByVal Target As Range)
Dim rng As Range
most = Now
For Each rng In Target
    If rng.Column = 2 Then 'if it's in B column
        Unique = True 'we'll assume it's unique
        Lastunique = Worksheets("Sheet2").Range("B:B").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        For i = 1 To Lastunique 'for each cell in the unique ID cache
            If rng.Value = Worksheets("Sheet2").Cells(i, 2).Value Then 'we check if it is equal
                Unique = False 'if yes, it is not unique
            End If
        Next
        If Unique Then Worksheets("Sheet2").Cells(Lastunique + 1, 2) = rng 'adds if it is unique
    End If
Next
MsgBox (Format(Now - most, "h:mm:ss"))
End Sub</code>

but none seem to work
 
Last edited:

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I'm not sure I can help you, but if you could send an example file (Using "Box.com", free file sharing) with your Data/formulas and expected results , I'll have a look.
 
Upvote 0
I'm not sure I can help you, but if you could send an example file (Using "Box.com", free file sharing) with your Data/formulas and expected results , I'll have a look.

It won't work we'd have to screenshare because the application I am using is licensed to my computer and you would need to install a trading appliaction aswell. MT4. You could try it on a free trial
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,222
Messages
6,123,717
Members
449,116
Latest member
Aaagu

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