Splitting a name using chr(10)

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
723
Office Version
  1. 2016
Platform
  1. Windows
I'm very new to R1C1, and I'm trying to split a name at the comma and use chr(10) between the first and last name.

This is my starting point
2.xls
F
2Martinez, Ernesto
Report

Next I created a few helper columns
VBA Code:
Cells(2, 10).FormulaR1C1 = "=RIGHT(RC[-4],FIND("","",RC[-4])-2)"
Cells(2, 11).FormulaR1C1 = "=LEFT(RC[-5],FIND("","",RC[-5])-1)"
2.xls
FGHIJK
2Martinez, ErnestoErnestoMartinez
Report
Cell Formulas
RangeFormula
J2J2=RIGHT(F2,FIND(",",F2)-2)
K2K2=LEFT(F2,FIND(",",F2)-1)

My goal would be the final result in 2,9 aka I2
2.xls
FGHIJK
2Martinez, ErnestoErnesto MarinezErnestoMartinez
Report
Cell Formulas
RangeFormula
J2J2=RIGHT(F2,FIND(",",F2)-2)
K2K2=LEFT(F2,FIND(",",F2)-1)


I tried
VBA Code:
Cells(2, 9).FormulaR1C1 = "=RIGHT(RC[-3],FIND("","",RC[-3])-2)" & Chr(10) & "=LEFT(RC[-3],FIND("","",RC[-3])-1)"
Cells(2, 9).FormulaR1C1 = "=RIGHT(RC[-3],FIND("","",RC[-3])-2)" & Chr(10) & "LEFT(RC[-3],FIND("","",RC[-3])-1)"
Cells(2, 9).FormulaR1C1 = "=RC[1]" & Chr(10) & "=RC[2]"
Cells(2, 9).FormulaR1C1 = "=RC[1]" & Chr(10) & "RC[2]"
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
It needs to be
VBA Code:
Cells(2, 9).FormulaR1C1 = "=RIGHT(RC[-3],FIND("","",RC[-3])-2) & Char(10) & LEFT(RC[-3],FIND("","",RC[-3])-1)"
 
Upvote 0
Solution
It needs to be
VBA Code:
Cells(2, 9).FormulaR1C1 = "=RIGHT(RC[-3],FIND("","",RC[-3])-2) & Char(10) & LEFT(RC[-3],FIND("","",RC[-3])-1)"
That worked, I forgot about the relative position changing. I am curios as to why I use Char(10) and not Chr(10).

In the past, I always would use Chr(10) -
VBA Code:
    Cells(2, 9).Value = "HELLO" & Chr(10) & "HELLO"
 
Upvote 0
Chr is a VBA function, whereas Char is the worksheet function.
 
Upvote 0

Forum statistics

Threads
1,215,646
Messages
6,125,999
Members
449,279
Latest member
Faraz5023

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