VBA: if cell contains number, return value from other cell

jcooooper

Board Regular
Joined
Mar 24, 2018
Messages
74
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Hopefully an easy one

In the below table, if a cell in named_range_2 has a number, I would like to return the corresponding value in named_range_1.

I am working with a datasets with 1000's of rows if that makes a difference


named_range_1named_range_2
def123
ghi
hjk
lmn22
op
qrs
lmn332
wxyz96541

For example, the above table would return

def
lmn
wxyz

(unique list, so the double "lmn" is ignored).


Any help would be greatly appreciated.

Thanks!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Which Excel version do you use?

Office 365 makes it easy:
Excel Formula:
=UNIQUE(FILTER($A$2:$A$9,ISNUMBER($B$2:$B$9),""))
 
Upvote 0
Microsoft 365 for enterprise. It says version 2008 which seems a bit dated?
 
Upvote 0
Ok great, thanks.

One more question, I would like to compare this unique list with another column, and remove those appear in that new column.
For example:

unique listnamed_range_3
deflmn
lmn
wxyz
So in this case, the unique list would just be

def
wxyz

given lmn appears in named_range_3

Is that possible with formulas or do we need VBA?

Thanks,
John
 
Upvote 0
You can refer to the output of the formula or do it within the formula. Assuming that named_range_3 is in column C

Excel Formula:
=FILTER(UNIQUE(FILTER($A$2:$A$9,ISNUMBER($B$2:$B$9),"")),COUNTIF($C$2:$C$9,UNIQUE(FILTER($A$2:$A$9,ISNUMBER($B$2:$B$9),"")))=0,"")

Or with LET if you have that function

Excel Formula:
=LET(x,UNIQUE(FILTER($A$2:$A$9,ISNUMBER($B$2:$B$9),"")),FILTER(x,COUNTIF($C$2:$C$9,x)=0,""))
 
Upvote 0
Last request, promise.

If I want to add one additional condition, so in addition removing duplicates, it only returns where named_range_4 starts with"GB" or "SG", how would I add that?
 
Upvote 0
Probably like this

VBA Code:
=LET(x,UNIQUE(FILTER($A$2:$A$9,ISNUMBER($B$2:$B$9),"")),FILTER(x,(COUNTIF($C$2:$C$9,x)=0)*((LEFT(x,2)="GB")+(LEFT(x,2)="SG")),""))
 
Upvote 0
Microsoft 365
Please put that in your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
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