Split Cell by Character Length excluding Spaces

mik1996

New Member
Joined
Mar 15, 2023
Messages
23
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
Hi, I'm looking for a formula or some coding that can split characters in excel excluding spaces, i work for a bank and the character limit is 30 for the beneficiary name (excluding spaces) so i need to cut and move anything after 30 characters excluding spaces in to the next column 'Beneficiary Name 2? ive tried a number of different ways but all of them include the spaces as characters, Is anyone able to help with this please?
Benficiary NameBenficiary Name 2
Client SSAI Account Nuclear Banks Services and Solutions ALLLFSM
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
For example, in B2
Excel Formula:
=LEFT(A2,MAX(IF(LEN(SUBSTITUTE(LEFT(A2,{30,31,32,33,34,35,36,37,38,39})," ",""))<31,{30,31,32,33,34,35,36,37,38,39},"")))

This deals with a max of 10 spaces; if you feel that is not enough then extend that 2 arrays of constants adding more options

PS not sure that {30,31,32,33,34,35,36,37,38,39} is the correct syntax for an array of constants

MULTI_C30319.xlsm
ABC
1Benficiary NameBenficiary Name2
2Client SSAI Account Nuclear Banks Services and Solutions ALLLFSMClient SSAI Account Nuclear Banks S
3
4
Sheet2
Cell Formulas
RangeFormula
B2B2=LEFT(A2,MAX(IF(LEN(SUBSTITUTE(LEFT(A2,{30,31,32,33,34,35,36,37,38,39})," ",""))<31,{30,31,32,33,34,35,36,37,38,39},"")))
 
Upvote 0
Hi,

Have you tried to use from the main menu Text to Columns ...?
thanks, yes i have tried this but again when i use text2columns it includes the spaces as characters so when i select 30 its including the spaces aswell if that makes sense
 
Upvote 0
But ...
Have you used the choice DELIMITED ... followed by the choice SPACES ... before indicating the destination ...?
 
Upvote 0
Excel Formula:
=LEFT(A2,MAX(IF(LEN(SUBSTITUTE(LEFT(A2,{30,31,32,33,34,35,36,37,38,39})," ",""))<31,{30,31,32,33,34,35,36,37,38,39},"")))
That works great actually thanks so much, sorry just realised i would also like split anything after the 30 characters (excl spaces) to be moved into another column is there another code i can use to do that?
 
Upvote 0
But ...
Have you used the choice DELIMITED ... followed by the choice SPACES ... before indicating the destination ...?
Go back and read the question again. I think you may have misunderstood it.
They are NOT trying to split after every space. I believe they want to split after 30 characters, but not in the middle of a word (so it may be less than 30 characters, depending on the value).
 
Upvote 0
i would also like split anything after the 30 characters (excl spaces) to be moved into another column is there another code i can use to do that?
In C2:
Excel Formula:
=SUBSTITUTE(A2,B2,"")

MULTI_C30319.xlsm
ABC
1Benficiary NameBenficiary Name2Next
2Client SSAI Account Nuclear Banks Services and Solutions ALLLFSMClient SSAI Account Nuclear Banks Services and Solutions ALLLFSM
3
Sheet2
Cell Formulas
RangeFormula
B2B2=LEFT(A2,MAX(IF(LEN(SUBSTITUTE(LEFT(A2,{30,31,32,33,34,35,36,37,38,39})," ",""))<31,{30,31,32,33,34,35,36,37,38,39},"")))
C2C2=SUBSTITUTE(A2,B2,"")
 
Upvote 0
Solution
In C2:
Excel Formula:
=SUBSTITUTE(A2,B2,"")

MULTI_C30319.xlsm
ABC
1Benficiary NameBenficiary Name2Next
2Client SSAI Account Nuclear Banks Services and Solutions ALLLFSMClient SSAI Account Nuclear Banks Services and Solutions ALLLFSM
3
Sheet2
Cell Formulas
RangeFormula
B2B2=LEFT(A2,MAX(IF(LEN(SUBSTITUTE(LEFT(A2,{30,31,32,33,34,35,36,37,38,39})," ",""))<31,{30,31,32,33,34,35,36,37,38,39},"")))
C2C2=SUBSTITUTE(A2,B2,"")
thats exactly what i needed, thank you for all your help much appreciated!
 
Upvote 0

Forum statistics

Threads
1,215,004
Messages
6,122,659
Members
449,091
Latest member
peppernaut

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