Subtract two strings from two different cells VBA

GirishDhruva

Active Member
Joined
Mar 26, 2019
Messages
308
Hi Everyone,

Can we subtract two cells which contains string in it.
Like,
[TABLE="width: 500"]
<tbody>[TR]
[TD]Column-A[/TD]
[TD]Column-B[/TD]
[TD]Column-C[/TD]
[/TR]
[TR]
[TD]abc_def_ghi[/TD]
[TD]_def_ghi[/TD]
[TD]abc[/TD]
[/TR]
[TR]
[TD]asdf123_abca[/TD]
[TD]_abca[/TD]
[TD]asdf123[/TD]
[/TR]
[TR]
[TD]afshqw_pl[/TD]
[TD]afsh_[/TD]
[TD]pl[/TD]
[/TR]
[TR]
[TD]asdff_1234[/TD]
[TD]_1234[/TD]
[TD]asdff[/TD]
[/TR]
</tbody>[/TABLE]

where Column(C) = Column(A)-Column(B)

Regards,
Dhruva
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
How about
=SUBSTITUTE(A2,B2,"")

Although your 3rd result looks wrong.
 
Upvote 0
How about
Code:
Sub GirishDhruva()
   With Range("C2", Range("A" & Rows.Count).End(xlUp).Offset(, 2))
      .Value =  Evaluate(Replace(Replace("if(@a="""","""",SUBSTITUTE(@a,@b,""""))",  "@a", .Offset(, -2).Address), "@b", .Offset(, -1).Address))
   End With
End Sub
 
Last edited:
Upvote 0
Ya it worked but if i have like below data then how that can be done


[TABLE="width: 500"]
<tbody>[TR]
[TD]abc_efg.xyz[/TD]
[TD]_efg.xyz[/TD]
[TD]abc[/TD]
[/TR]
[TR]
[TD]1234_efg.xyz[/TD]
[TD][/TD]
[TD]1234[/TD]
[/TR]
[TR]
[TD]qwerty_efg.xyz[/TD]
[TD][/TD]
[TD]qwerty[/TD]
[/TR]
[TR]
[TD]123asdf_egf.xyz[/TD]
[TD][/TD]
[TD]123asdf[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Please explain EXACTLY what you want rather then "moving the goal posts" as you normally do.
 
Upvote 0
Hi @Fluff i need in both the way for two sheets.
Like in 1st sheet i need to perform as per #1st Post and in 2nd sheet i need to perform as per #5th post

Sorry for confusing you

Regards
Dhruv
 
Upvote 0
Assuming that _efg.xyz is in B2 try
Code:
Sub GirishDhruva()
   With Range("C2", Range("A" & Rows.Count).End(xlUp).Offset(, 2))
      .Value = Evaluate(Replace("if(@a="""","""",SUBSTITUTE(@a,$B$2,""""))", "@a", .Offset(, -2).Address))
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
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