Having trouble with Right Left Mid

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
727
Office Version
  1. 2016
Platform
  1. Windows
I don't understand why Right sometimes works and other times not.
2.xls
FGHI
2Martinez, ErnestoErnesto Martinez
3Alvarez, CarlosCarlos Alvarez
4Estala, ChrisChris Estala
5Garcia, Anthonythony Garcia
6Perez, Patrickrick Perez
7Schultschik, Christian Christian Schultschik
8SMID, RONDANDA SMID
9Vela, Davinvin Vela
10Atwood, Bret Bret Atwood
11Gallaway, MatthewMatthew Gallaway
12Hale, Andrewrew Hale
Report
Cell Formulas
RangeFormula
I2:I12I2=RIGHT(F2,FIND(",",F2)-2) & CHAR(10) & LEFT(F2,FIND(",",F2)-1)

I was reading about InStr, and was able to get it to work using Debug.Print, I just don't know how to use it with a WorkSheet.
VBA Code:
Debug.Print Left(Cells(7, 6), InStr(Cells(7, 6), ",") - 1)
Debug.Print Mid(Cells(7, 6), InStr(Cells(7, 6), ",") + 2)
If it makes a difference, I'm trying my hand at writing all formulas in R1C1.

This is my origial code that Fluff helped me with -
VBA Code:
Sheets("Report").Range(Cells(2, 9), Cells(LR2, 9)).FormulaR1C1 = "=RIGHT(RC[-3],FIND("","",RC[-3])-2) & Char(10) & LEFT(RC[-3],FIND("","",RC[-3])-1)"

I tried replacing Right with Mid in the above, but as you probably have guessed, that did not work.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Your error is Right counts from the right of string not the left , find gives you the number from the left of the string. try this formula:
Excel Formula:
=RIGHT(F2,LEN(F2)-FIND(",",F2)) & CHAR(10) & LEFT(F2,FIND(",",F2)-1)
 
Upvote 0
Try this:
VBA Code:
Sheets("Report").Range(Cells(2, 9), Cells(LR2, 9)).FormulaR1C1 = "=MID(RC[-3],FIND("","",RC[-3])+2,LEN(RC[-3]))&CHAR(10)&LEFT(RC[-3],FIND("","",RC[-3])-1)"
 
Upvote 0
Solution

Forum statistics

Threads
1,223,954
Messages
6,175,603
Members
452,658
Latest member
GStorm

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