Bulk Text Macro - Require Assistance in separating each line in HTML

JackBTM

New Member
Joined
Apr 6, 2021
Messages
8
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi everyone,

Hope you've all had a wonderful weekend.

I have received 250 cells which I need to format into HTML for the system I use on my computer for work. Each line/paragraph needs to start with <p> and close with a </p>, however the below macro I have tried using is putting <p></p> in between each paragraph in the space sections. I need this to be gone as the system we use won't accept empty <p></p> lines.

Is anyone able to assist or fix the below please? Would be much appreciated. Will attach an image of how it looks and the macro I am using.

Code:
Sub aTest()
    Dim rCell As Range, spl As Variant, i As Long
   
    For Each rCell In Selection
        spl = Split(rCell, Chr(10))
        For i = LBound(spl) To UBound(spl)
            spl(i) = Chr(60) & "p" & Chr(62) & spl(i) & Chr(60) & "/p" & Chr(62)
        Next i
        rCell = Join(spl, Chr(10))
    Next rCell
    Selection.ColumnWidth = 200
    Selection.EntireRow.AutoFit
    Selection.EntireColumn.AutoFit
End Sub
 

Attachments

  • Capture.JPG
    Capture.JPG
    14.3 KB · Views: 9

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Hi
what about
VBA Code:
Sub aTest()
    Dim rCell As Range, spl As Variant, i As Long

    For Each rCell In Selection
        spl = Split(rCell, Chr(10))

        For i = LBound(spl) To UBound(spl)
            If spl(i) <> "" Then
                spl(i) = Chr(60) & "p" & Chr(62) & spl(i) & Chr(60) & "/p" & Chr(62)
            End If
        Next i
        rCell = Join(spl, Chr(10))

    Next rCell
    Selection.ColumnWidth = 200
    Selection.EntireRow.AutoFit
    Selection.EntireColumn.AutoFit
End Sub
 
Upvote 0
Hi
what about
VBA Code:
Sub aTest()
    Dim rCell As Range, spl As Variant, i As Long

    For Each rCell In Selection
        spl = Split(rCell, Chr(10))

        For i = LBound(spl) To UBound(spl)
            If spl(i) <> "" Then
                spl(i) = Chr(60) & "p" & Chr(62) & spl(i) & Chr(60) & "/p" & Chr(62)
            End If
        Next i
        rCell = Join(spl, Chr(10))

    Next rCell
    Selection.ColumnWidth = 200
    Selection.EntireRow.AutoFit
    Selection.EntireColumn.AutoFit
End Sub

Thank you so much! This worked!!
 
Upvote 0
You are welcome
And thank you for the feedback
Be happy & safe
 
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Bulk Text Macro - Require Assistance in seperating each line in HTML
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Bulk Text Macro - Require Assistance in seperating each line in HTML
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.

My apologies - I posted on the site but a white filter came over my browser on the site, so I posted on here instead. I did not realise it had submitted.

I have messaged their Contact Team to see if they can delete the post - sorry once again!
 
Upvote 0
Would this do the same thing without any looping at all? (Assumes the data is in column D starting at row 2 - but easily editable)

VBA Code:
Sub Format_HTML()
  With Range("D2", Range("D" & Rows.Count).End(xlUp))
    .Value = Evaluate("substitute(substitute(""<p>""&" & .Address & "&""</p>"",char(10),""</p>"" & char(10)&""<p>""),""<p></p>"","""")")
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,837
Messages
6,121,883
Members
449,057
Latest member
Moo4247

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