Partially delete cell content, based on previous cell

ibTops

New Member
Joined
Sep 21, 2017
Messages
12
I'm dealing with 4 Columns with the following initial layout example:


[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD="align: center"]COLUMN S[/TD]
[TD="align: center"]COLUMN T[/TD]
[TD="align: center"]COLUMN U[/TD]
[TD="align: center"]COLUMN V[/TD]
[/TR]
[TR]
[TD="align: center"]01, 03, 21[/TD]
[TD="align: center"]01, 03, 21[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]08, 15[/TD]
[TD="align: center"]08, 15, 08[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]30, 33, 34[/TD]
[TD="align: center"]30, 33, 34, 30, 34[/TD]
[TD="align: center"]33[/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]09[/TD]
[TD="align: center"]09[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

I'd need, via either an equation or a macro, that the cells in Column V show the numbers I've highlighted in BLUE in each row.

Basically what's happening is that:

- If Column U = Empty, then Column T = Column S. This is fine because I do V = T, done.

- If Column U = NotEmpty, then Column T = Column S + (Column S - Column U). This is a problem, because what I'd need in Column V in these cases is only the part: Column S - Column U.


I hope that makes sense. Thanks in advance!!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Will column U always just be one number? If so, try:


Book1
STUV
201, 03, 2101, 03, 2101, 03, 21
308, 1508, 15,081508
430, 33, 3430, 33, 34,30, 343330, 34
5999
Sheet1
Cell Formulas
RangeFormula
V2=SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(","&SUBSTITUTE(SUBSTITUTE(S2,",",",,")," ","")&",",","&U2&","," "),","," "))," ",", ")


If not, I suspect you'll need a macro.
 
Upvote 0
My formula needs adjustment, will post back.
 
Last edited:
Upvote 0
My formula needs adjustment, will post back.

Sorry, got busy, here's my version, hope I understand correctly:


Excel 2010
STUV
101, 03, 2101, 03, 2101, 03, 21
208, 1508, 15,081508
330, 33, 3430, 33, 34,30, 343330, 34
4090909
521, 22, 23, 2421, 22, 23, 24, 252122, 23, 24
621, 22, 23, 2421, 22, 23, 24, 252521, 22, 23, 24
Sheet4
Cell Formulas
RangeFormula
V1=IF(U1="",S1,TRIM(SUBSTITUTE(SUBSTITUTE(" , "&S1,", "&U1,"")," , ","")))
 
Last edited:
Upvote 0
Thanks Eric, but I'm afraid Column U can be more than one number :(

AWESOME jtakw!! That's working great, except for these 2 examples (IDK why??? I've highlighted in orange the numbers I'm getting in V):


16, 35, 4116, 35, 41, 3516, 35, 41
03, 06, 09, 14, 16, 18, 21, 25, 28, 35, 38, 39, 41, 43, 4503, 06, 09, 14, 16, 18, 21, 25, 28, 35, 38, 39, 41, 43, 45, 03, 35, 38, 39, 43, 45

<colgroup><col><col><col><col><col></colgroup><thead>
[TH="align: center"][/TH]
[TH="align: center"]S[/TH]
[TH="align: center"]T[/TH]
[TH="align: center"]U[/TH]
[TH="align: center"]V[/TH]

</thead><tbody>
[TD="align: center"]1[/TD]

[TD="align: right"]16, 41[/TD]

[TD="align: center"]2[/TD]

[TD="align: right"]06, 09, 14, 16, 18, 21, 25, 28, 41[/TD]
[TD="align: right"] 03, 06, 09, 14, 16, 18, 21, 25, 28, 35, 38, 39, 41, 43, 45 [/TD]

[TD="align: center"][/TD]

[TD="align: right"][/TD]

</tbody>
Sheet4

Any ideas??
 
Upvote 0
I believe jtakw's formula also only works when there is one value in U. You'll need a UDF.

Open a copy of your workbook. Press Alt-F11 to open the VBA editor. From the menu click Insert > Module. Paste the following code into the window that opens:

Code:
Public Function ListSubtract(Orig As String, Remov As String)
Dim x As Variant, y As String, x1 As Variant

    x = Split(Replace(Orig, " ", ""), ",")
    y = "," & Replace(Remov, " ", "") & ","
    
    For Each x1 In x
        If InStr(y, "," & x1 & ",") = 0 Then ListSubtract = ListSubtract & x1 & ", "
    Next x1
    
    ListSubtract = Left(ListSubtract, Len(ListSubtract) - 2)
End Function
Press Alt-Q to close the editor. Back on your Excel sheet, enter this formula:

Excel 2012
STUV
16, 35, 4116, 35, 41, 35
03, 06, 09, 14, 16, 18, 21, 25, 28, 35, 38, 39, 41, 43, 4503, 06, 09, 14, 16, 18, 21, 25, 28, 35, 38, 39, 41, 43, 45, 03, 35, 38, 39, 43, 45

<colgroup><col style="width: 25pxpx"><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="align: center"]01, 03, 21[/TD]
[TD="align: center"]01, 03, 21[/TD]
[TD="align: center"][/TD]
[TD="align: center"]01, 03, 21[/TD]

[TD="align: center"]2[/TD]
[TD="align: center"]08, 15[/TD]
[TD="align: center"]08, 15, 08[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]08[/TD]

[TD="align: center"]3[/TD]
[TD="align: center"]30, 33, 34[/TD]
[TD="align: center"]30, 33, 34, 30, 34[/TD]
[TD="align: center"]33[/TD]
[TD="align: center"]30, 34[/TD]

[TD="align: center"]4[/TD]
[TD="align: center"]9[/TD]
[TD="align: center"]9[/TD]
[TD="align: right"][/TD]
[TD="align: center"]9[/TD]

[TD="align: center"]5[/TD]

[TD="align: right"]16, 41[/TD]
[TD="align: center"]35[/TD]

[TD="align: center"]6[/TD]

[TD="align: right"]06, 09, 14, 16, 18, 21, 25, 28, 41[/TD]
[TD="align: center"]03, 35, 38, 39, 43, 45[/TD]

</tbody>
Sheet1

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]V1[/TH]
[TD="align: left"]=listsubtract(S1,U1)[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]



Hope this helps.
 
Upvote 0
Thanks Eric, but I'm afraid Column U can be more than one number :(

AWESOME jtakw!! That's working great, except for these 2 examples (IDK why??? I've highlighted in orange the numbers I'm getting in V):


16, 35, 41
16, 35, 41, 35
16, 35, 41
03, 06, 09, 14, 16, 18, 21, 25, 28, 35, 38, 39, 41, 43, 45
03, 06, 09, 14, 16, 18, 21, 25, 28, 35, 38, 39, 41, 43, 45, 03, 35, 38, 39, 43, 45

<tbody>
[TH="align: center"][/TH]
[TH="align: center"]S
[/TH]
[TH="align: center"]T
[/TH]
[TH="align: center"]U
[/TH]
[TH="align: center"]V
[/TH]

[TD="align: center"]1
[/TD]

[TD="align: right"]16, 41
[/TD]

[TD="align: center"]2
[/TD]

[TD="align: right"]06, 09, 14, 16, 18, 21, 25, 28, 41
[/TD]
[TD="align: right"] 03, 06, 09, 14, 16, 18, 21, 25, 28, 35, 38, 39, 41, 43, 45
[/TD]

[TD="align: center"][/TD]

[TD="align: right"][/TD]

</tbody>
Sheet4

Any ideas??

My formula will work with either a single 2 digit number Or multiple 2 digit numbers separated by a coma and space in Column U; however, it will Only work if the set of numbers in Column U is in the Exact same order as in Column S with no Other numbers in between, as in these samples you showed above, where my formula Will fail.

So you're better off with Eric's UDF in that situation.
 
Upvote 0

Forum statistics

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