Select unique values and the last one from them

rguy84

Board Regular
Joined
May 18, 2011
Messages
112
Say you have a list of names A1:Axxx, there are a few duplicates. You will be using that list to populate a listbox. B1:Bxxx holds a value (doesnt quite matter here), the last value is selected. So if A1,A4, A7 says Mary, A7,b7's Mary is used vs A1 or A4.

How do I do this in VBA? So far:
Code:
    With lbox
        .ColumnCount = 2
        .RowSource = "A1:B" & Sheets("Contact").Range("B" & Rows.Count).End(xlUp).Row
    End With
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
try this macro

Code:
Sub test()
Dim last As Range, cfind As Range
Set last = Range("A1").End(xlDown)
Set cfind = Cells.Find(what:="Mary", lookat:=xlWhole)
Set cfind = Cells.FindPrevious(after:=last)
MsgBox cfind.Address
End Sub
Code:
 
Upvote 0
will this not work


Code:
Sub test() Dim last As Range, cfind As Range,nname as string
nname="Mary"
 Set last = Range("A1").End(xlDown)
 Set cfind = Cells.Find(what:=nname, lookat:=xlWhole)
 Set cfind = Cells.FindPrevious(after:=last) M
sgBox cfind.Address
 End Sub
 
Upvote 0
yes nname is a variable. you enter any other name in this code

nname=" "

if you want you change this stament as

name=inputbox("type the name you want e.g. Mary")
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,795
Members
452,943
Latest member
Newbie4296

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