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:


COLUMN SCOLUMN TCOLUMN UCOLUMN V
01, 03, 2101, 03, 21
08, 1508, 15, 0815
30, 33, 3430, 33, 34, 30, 3433
0909

<tbody>
</tbody>

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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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):


STUV
116, 35, 4116, 35, 41, 3516, 4116, 35, 41
203, 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, 4506, 09, 14, 16, 18, 21, 25, 28, 4103, 06, 09, 14, 16, 18, 21, 25, 28, 35, 38, 39, 41, 43, 45

<colgroup><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</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
101, 03, 2101, 03, 2101, 03, 21
208, 1508, 15, 081508
330, 33, 3430, 33, 34, 30, 343330, 34
4999
516, 35, 4116, 35, 41, 3516, 4135
603, 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, 4506, 09, 14, 16, 18, 21, 25, 28, 4103, 35, 38, 39, 43, 45

<colgroup><col style="width: 25pxpx"><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
V1=listsubtract(S1,U1)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>



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):


S
T
U
V
1
16, 35, 41
16, 35, 41, 35
16, 41
16, 35, 41
2
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
06, 09, 14, 16, 18, 21, 25, 28, 41
03, 06, 09, 14, 16, 18, 21, 25, 28, 35, 38, 39, 41, 43, 45

<tbody>
</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,215,106
Messages
6,123,124
Members
449,096
Latest member
provoking

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