Trying to apply two substitutes to one cell, Left becomes Right, and Right becomes Left

jonathan92591

Board Regular
Joined
Oct 27, 2011
Messages
65
Excel version:Excel 2016
Computer operating system:Windows 7
Sample data:Sheet1

*A
1Text Needed to Change
224" Left Hinge Built-In ADA Compliant Beverage Center
324" Right Hinge Built-In ADA Compliant Beverage Center
424" Left Hinge Built-In ADA Compliant Beverage Center

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4
Formulas/functions being used: = SUBSTITUTE(SUBSTITUTE(A2,"Left","Right"),"Right","Left")
Current results:Sheet1

*AB
1Text Needed to ChangeAttempt at Changing Text
2XXX24" Left Hinge Built-In ADA Compliant Beverage Center
3XXX24" Left Hinge Built-In ADA Compliant Beverage Center
424" Left Hinge Built-In ADA Compliant Beverage Center24" Left Hinge Built-In ADA Compliant Beverage Center

<tbody>
</tbody>

Spreadsheet Formulas
CellFormula
B2=SUBSTITUTE(SUBSTITUTE(A2,"Left","Right"),"Right","Left")
B3=SUBSTITUTE(SUBSTITUTE(A3,"Left","Right"),"Right","Left")
B4=SUBSTITUTE(SUBSTITUTE(A4,"Left","Right"),"Right","Left")

<tbody>
</tbody>

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4
My goal:Change "Left" to "Right." And, Change "Right" to "Left."
Error message:No error message.
How error occurred:Not working correctly.
Generated in:Excel
Thank you, JT

<tbody>
</tbody>
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi,

Another way:


Excel 2010
ABC
1Text Needed to Change
224" Left Hinge Built-In ADA Compliant Beverage Center24" Right Hinge Built-In ADA Compliant Beverage Center
324" Right Hinge Built-In ADA Compliant Beverage Center24" Left Hinge Built-In ADA Compliant Beverage Center
424" Left Hinge Built-In ADA Compliant Beverage Center24" Right Hinge Built-In ADA Compliant Beverage Center
Sheet1
Cell Formulas
RangeFormula
C2=IF(ISNUMBER(SEARCH("Left",A2)),SUBSTITUTE(A2,"Left","Right",1),SUBSTITUTE(A2,"Right","Left",1))
 
Upvote 0
As long as no cells contain both "Left" and "Right", this will work:

=IF(NOT(ISERR(FIND("Left",A1,1))),SUBSTITUTE(A1,"Left","Right"),SUBSTITUTE(A1,"Right","Left"))

With the nested SUBSTITUTE, you were changing Left to Right, and then right back to Left again.

This statement first checks if the cell has "Left", and if it does, changes "Left" to "Right", and if not, changes "Right" to "Left".
 
Upvote 0
As long as no cells contain both "Left" and "Right", this will work:

=IF(NOT(ISERR(FIND("Left",A1,1))),SUBSTITUTE(A1,"Left","Right"),SUBSTITUTE(A1,"Right","Left"))

With the nested SUBSTITUTE, you were changing Left to Right, and then right back to Left again.

This statement first checks if the cell has "Left", and if it does, changes "Left" to "Right", and if not, changes "Right" to "Left".

Excellent point.
 
Upvote 0

Forum statistics

Threads
1,216,076
Messages
6,128,670
Members
449,463
Latest member
Jojomen56

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