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,
Column-AColumn-BColumn-C
abc_def_ghi_def_ghiabc
asdf123_abca_abcaasdf123
afshqw_plafsh_pl
asdff_1234_1234asdff

<tbody>
</tbody>

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

Regards,
Dhruva
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
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


abc_efg.xyz_efg.xyzabc
1234_efg.xyz1234
qwerty_efg.xyzqwerty
123asdf_egf.xyz123asdf

<tbody>
</tbody>
 
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,214,819
Messages
6,121,729
Members
449,049
Latest member
MiguekHeka

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