String of numerical values based on values in other cells

ChristineJ

Well-known Member
Joined
May 18, 2009
Messages
761
Office Version
  1. 365
Platform
  1. Windows
Trying to return a string of values using this basic example below:

Cell B2 contains a string of cell references separated by commas. (The actual cell references and the number of cell references can vary.)
Example: B12, K22, G9, F3, E10, A24, C11, M1, F6, J19, G12, H14
Each of these cells contains a numerical value.

Cell B4 contains a string of values separated by commas. (The amounts and the number of amounts can vary.)
Example: 4, 7, 9, 15, 18

Cell B6: Is there a formula (or VBA) so that cell B6 returns only the values from cell B4 that are NOT contained in one of the cells in B2?
Example: All of the cells listed in B2 contain a value over 20 except the following: G9 = 4; M1 = 3; H14 = 15
Result: Cell B6 shows 7, 9, 18

Thanks!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Try this:
Book1
ABCDEFGHIJKLMNO
122Results
2CellsB12, K13, G9, F3, E10, A14, C11, M1, F6, J15, G12, H147
36618
4Values4, 7, 9, 15, 18
5
611
7
8
955
109
114
123325
1344
148835
1515
Sheet1
Cell Formulas
RangeFormula
O2:O3O2=LET(btwo,CELL("contents",INDIRECT(TEXTSPLIT(B2,,", ") ))+0,bfour, TEXTSPLIT(B4,,", ")+0,FILTER(bfour,ISNUMBER(MATCH(bfour,btwo,0))=FALSE))
Dynamic array formulas.

And if some error trapping is needed when everything in B4 matches something, so the list would be empty, or nothing is in B4, this version should handle those situations by returning a blank.
Excel Formula:
=LET(btwo,CELL("contents",INDIRECT(TEXTSPLIT(B2,,", ") ))+0,bfour, TEXTSPLIT(B4,,", ")+0,IFERROR(FILTER(bfour,ISNUMBER(MATCH(bfour,btwo,0))=FALSE,""),""))
 
Last edited:
Upvote 0
Solution
Unbelievable - works great! Thank you...that is not something I would ever have figured out on my own! C
 
Upvote 0
1712588678132.png


VBA code:
VBA Code:
Sub FindNumbers()
Dim A, S, K, T&, Ta&, Op$

S = Split(Range("B2"), ", ")
A = Split(Range("B4"), ",")

For T = 0 To UBound(A)
K = A(T) + 0
    For Ta = 0 To UBound(S)
    If Range(Trim(S(Ta))) = K Then K = "": Exit For
    Next Ta
If K <> "" Then Op = Op & "," & K
Next T
If Op <> "" Then Range("B6") = Mid(Op, 2)
End Sub
 
Upvote 0
View attachment 109647

VBA code:
VBA Code:
Sub FindNumbers()
Dim A, S, K, T&, Ta&, Op$

S = Split(Range("B2"), ", ")
A = Split(Range("B4"), ",")

For T = 0 To UBound(A)
K = A(T) + 0
    For Ta = 0 To UBound(S)
    If Range(Trim(S(Ta))) = K Then K = "": Exit For
    Next Ta
If K <> "" Then Op = Op & "," & K
Next T
If Op <> "" Then Range("B6") = Mid(Op, 2)
End Sub
Amazing - this works very well! I like that it returns all the results horizontally in one cell. Thank you SO much. c
 
Upvote 0
I didn't realize you preferred the list in a single cell. A formula mod to do that:
MrExcel_20240408.xlsx
ABCDEFGHIJKLMNO
122Results
2CellsB12, K13, G9, F3, E10, A14, C11, M1, F6, J15, G12, H147, 23, 41
366
4Values4, 7, 9, 15, 18, 23, 41
5
611
7
8
955
109
114
127718
1344
148835
1515
Sheet1
Cell Formulas
RangeFormula
O2O2=LET(btwo,CELL("contents",INDIRECT(TEXTSPLIT(B2,,", ") ))+0,bfour, TEXTSPLIT(B4,,", ")+0,lst,IFERROR(FILTER(bfour,ISNUMBER(MATCH(bfour,btwo,0))=FALSE,""),""),TEXTJOIN(", ",,lst))
 
Upvote 0
Another refinement to handle B4 inputs that might be comma or comma-space separated, and to sort the final outputs. Is there any chance that the B4 inputs might contain duplicate values? If so, what is the expectation?...that duplicates are considered as a singular value, or that a duplicate pair would need a corresponding duplicate pair from the B2 cell references to cancel them both? I don't know if that scenario is possible, but thought that I would ask.
MrExcel_20240408.xlsx
ABCDEFGHIJKLM
122
2CellsB12, K13, G9, F3, E10, A14, C11, M1, F6, J15, G12, H14
366
4Values4,23, 18, 37,13,12, 1,77, 66
5
6Results1, 12, 13, 23, 3711
7
8
955
109
114
127718
1344
148835
1515
Sheet1
Cell Formulas
RangeFormula
B6B6=LET(btwo,CELL("contents",INDIRECT(TRIM(TEXTSPLIT(B2,,",")))),bfour,TEXTSPLIT(B4,,",")+0,TEXTJOIN(", ",,IFERROR(SORT(FILTER(bfour,ISNUMBER(MATCH(bfour,btwo,0))=FALSE,"")),"")))
 
Upvote 0

Forum statistics

Threads
1,215,212
Messages
6,123,654
Members
449,113
Latest member
Hochanz

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