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

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
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")),""))

I tried this but couldn't get it to work. Do I need to substitute anything in apart from the column references?

For example, I pasted the bellow table in cell A2.


named_range_1named_range_2named_range_3
ABC
123​
SG123
DEFHK456
GHI
456​
JKL
789​
GB789

Was hoping it would return:

ABC
JKL

but get the #name error

Do I need to substitute something in for "x"?

Many thanks!
 
Upvote 0
How about
Excel Formula:
=FILTER(A2:A10,(B2:B10<>"")*((LEFT(C2:C10,2)="GB")+(LEFT(C2:C10,2)="SG")))
 
Upvote 0
How about
Excel Formula:
=FILTER(A2:A10,(B2:B10<>"")*((LEFT(C2:C10,2)="GB")+(LEFT(C2:C10,2)="SG")))

Works perfect on the smaller data set, but when I use in the real world with my named ranges (1000s of rows) I get the #CALC! error. Is that just the size of the calculation do you think?
 
Upvote 0
That error suggests that there are no rows which meat the criteria.
 
Upvote 0
Thanks for updating your profile.

You have mentioned named ranges in all your questions. If you have those, it makes sense to me to use them in your formulas as it then does not matter what columns they are in or what rows they occupy.

From the descriptions it seems that named_range_1, named_range_2 and named_range_4 must all contain the same number of rows since you are trying to compare what is on the same row in each of those ranges.
named_range_3 I am not so sure about?

I am not sure I have grasped the exact details of your requirements, but could you use some thing like this?

jcooooper.xlsm
ABCDEFGH
1named_range_1named_range_2named_range_3named_range_4Post 1 QnPost 4 QnPost 8 Qn
2def123lmndefdefABC
3ghiwxyzlmnABCJKL
4def456wxyzPQR
5hjkABCJKL
6lmn22SG33PQR
7opJKL
8qrs
9lmn332
10wxyz96541
11ABC123SG123
12XYZHK456
13PQR456
14JKL789GB789
Sheet1
Cell Formulas
RangeFormula
F2:F7F2=UNIQUE(FILTER(named_range_1,ISNUMBER(named_range_2),""))
G2:G5G2=LET(f,UNIQUE(FILTER(named_range_1,ISNUMBER(named_range_2),"")),FILTER(f,ISNA(MATCH(f,named_range_3,0)),""))
H2:H3H2=LET(f,FILTER(named_range_1,ISNUMBER(named_range_2)*ISNUMBER(FIND(LEFT(named_range_4&".",2),"|GB|SG|")),""),UNIQUE(FILTER(f,ISNA(MATCH(f,named_range_3,0)),"")))
Dynamic array formulas.
Named Ranges
NameRefers ToCells
named_range_1=Sheet1!$A$2:$A$14F2:H2
named_range_2=Sheet1!$B$2:$B$14F2:H2
named_range_3=Sheet1!$C$2:$C$3G2:H2
named_range_4=Sheet1!$D$2:$D$14H2
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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