VBA to add words / bits my the words in a cell

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
I have data in cell K2 that looks like this:

K
2Buckle up -- this double-strap satchel is equal parts fashionable and functional. From Dooney & Bourke.

Main entry zip closure, double handles, tassels, front and back buckles, back slip pocket, leather patch logo, four feet
Lined interior, two front-wall slip pockets, back-wall zip pocket and slip pocket, key hook
Measures approximately 10"L x 14"W x 6"D with an 8" handle drop; weighs 2 lbs, 7 oz
Body/trim 100% leather; lining 100% cotton
Imported

and I need it to look like this so i can upload it:


K
2<p>Want star power? Slide your feet in these pointy-toe mules and instantly upgrade your look with radiant shine. From Katy Perry.</p>

<ul>
<li>Style: The Tarin</li>
<li>Toe cap, star print</li>
<li>Padded insole, scored bottom</li>
<li>Approximately 0.5&quot;H heel</li>
<li>Fit: true to size</li>
<li>Fabric/man-made upper; man-made lining; man-made/fabric sole</li>
<li>Imported</li>
</ul>


The rules are quite simple,
the first lot of data in the cell will start without any spaces before it, it might be one word one sentence or several sentences but there will be no line break,
This data needs to have added at the beginning <p> and at the end </p>
as shown above,
then we get page breaks, there can be one or more page breaks before the data starts again, but all this data needs to be held with the text <ul> and </ul>
again as above,

then any data in that area has to start each new line break line with a <li> and end it with </li>
again as above.
please use the examples above as what I'm trying to achieve.


I hope that's clear, I really could do with some help here so please help if you can.
Thanks
Tony
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hmm, with O365 I've made something like this:

Cell Formulas
RangeFormula
B2B2=AddHTML(TRANSPOSE(TEXTSPLIT(A2,CHAR(10))),,"")


In NameManager create new range named AddHTML with reference to:

Excel Formula:
=LAMBDA(xEntryVal,licznik,xWynik,LET(xLicznik, IF(licznik, licznik, 1), myStr, xEntryVal, xWyn, xWynik, xDodaj, IF(xLicznik = 1, "<p>" & INDEX(myStr, xLicznik) & "</p>" & CHAR(10) & CHAR(10) & "<ul>" & CHAR(10), "<li>" & INDEX(myStr, xLicznik) & "</li>" & CHAR(10)), xTemp, xWyn & xDodaj, IF(xLicznik < COUNTA(myStr), AddHTML(myStr, xLicznik + 1, xTemp), xTemp & "</ul>")))
 
Upvote 0
Solution
Wow,
thank you for this KoKOSek,
looks brilliant, i'll give it a try :-)
Tony
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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