Split Cell out into specific character count and concatenate

EAG1

New Member
Joined
Feb 12, 2021
Messages
23
Office Version
  1. 365
Platform
  1. Windows
Hello all,

We are trying to automate some product titles and could do with some help. The data below is what we have and the following is what we want the results to be. Essentially we have a character limit of 80 and the columns in yellow are what we are looking at. The "combined" column G is counted and this (column H) is then taken away from the total count of 80 to give us how many spare characters we have left (column I). We then want to split the model data (column J) out into the amount of character left (splitting via the comma) but then turning the comma & space into a single space. See further down

1672841251784.png


The output we are looking for is below. Hopefully it makes sense.

1672841539560.png


Please let me know if you need any further info or if anything doesn't make sense.

Thanks, EAG1.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Do you want a formula or macro solution?
Hello, I assumed it would need to be a macro solution, however if someone can suggest a formula to do the job that will also be fine. Thanks
 
Upvote 0
No macro needed.

Excel Formula:
=IF(MID(SUBSTITUTE(G2&" "&J2,",",""),80+1,1)=" ",LEFT(SUBSTITUTE(G2&" "&J2,",",""),80),(G2&" " & LEFT(SUBSTITUTE(J2,",",""),SEARCH("#",SUBSTITUTE(LEFT(SUBSTITUTE(J2,",",""),80-LEN(G2 & " "))," ","#",(80-LEN(G2)-1)-LEN(SUBSTITUTE(LEFT(SUBSTITUTE(J2,",",""),80-LEN(G2 & " "))," ",""))))-1)))

All you need is the "Combined" text, the model data text, and the max number of characters (80). Don't need the Count and Characters Left columns.

First, there's an IF - if the 81st character (after stripping commas) is a [space], then get the left 80 characters. If not, this formula ... strips the commas, counts the spaces, finds the last space before the max character number and gets all characters up to that number.

I'm on Excel 2016. Prople with more recent versions and functions may be able to do something sexier.
 
Upvote 0
Macro if you prefer ... in cell, type "=GetDesc(G2,J2,80)"

VBA Code:
Public Function GetDesc(Combined$, ModelData$, MaxChar%) As String
Dim strTotal$
    strTotal = Combined & " " & Replace(ModelData, ",", "")
    GetDesc = Left(strTotal, MaxChar)
    If Mid(strTotal, MaxChar + 1, 1) = " " Then Exit Function
    GetDesc = Left(GetDesc, InStrRev(GetDesc, " ") - 1)
End Function
 
Upvote 0
Hello @mmhill, thank you for your reply.

I can see that it works for the first instance but how do I get it to work for the subsequent titles? We have more model data than will fit into a single title so need this split across multiple titles (see the output screenshot). The combined words will stay the same each time but we will need to break the models out into multiple titles until they are all used up. Hope that makes sense.

Thank you for your help, it is greatly appreciated.
 
Upvote 0

Forum statistics

Threads
1,215,453
Messages
6,124,930
Members
449,195
Latest member
Stevenciu

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