Convert cell data to html

badam1212

New Member
Joined
Jul 25, 2017
Messages
19
I'm trying to use the code below to convert data in my worksheet to html. I tried pasting in visual basic, but when I highlight and run, I get an error (can't execute in break mode). Beginner, so please let me what I'm not doing here. Thank you!

My objective is to be able to convert cell data to html within the workbook. Example of cell data:

[TABLE="width: 320"]
<tbody>[TR]
[TD="width: 64"]Men's Sizes[/TD]
[TD="width: 64"]XS[/TD]
[TD="width: 64"]S[/TD]
[TD="width: 64"]M[/TD]
[TD="width: 64"]L[/TD]
[/TR]
[TR]
[TD]Size (Shirts & Tops)[/TD]
[TD]30/32-32/34[/TD]
[TD]34/36-36/38[/TD]
[TD]38/40-40/42[/TD]
[TD]42/44-44/46[/TD]
[/TR]
[TR]
[TD]Chest[/TD]
[TD]31"-33"[/TD]
[TD]34"-37"[/TD]
[TD]37"-40"[/TD]
[TD]40"-44"[/TD]
[/TR]
[TR]
[TD]Waist[/TD]
[TD]27"-29"[/TD]
[TD]30"-32"[/TD]
[TD]32"-35"[/TD]
[TD]35"-39"[/TD]
[/TR]
[TR]
[TD]Hip[/TD]
[TD]32"-43"[/TD]
[TD]35"-37"[/TD]
[TD]37"-40"[/TD]
[TD]40"-44"[/TD]
[/TR]
[TR]
[TD]Inseam[/TD]
[TD]31.9"[/TD]
[TD]32.1"[/TD]
[TD]32.3"[/TD]
[TD]32.5"[/TD]
[/TR]
</tbody>[/TABLE]

Code:
Option Explicit

Sub ConvertToHTML()
Dim RowStart As Integer
Dim ColStart As Integer
Dim ColCount As Integer
Dim RowCount As Integer
Dim RowEnd As Integer
Dim ColEnd As Integer
Dim ctrRow As Integer
Dim ctrCol As Integer
Dim IndentString As String
Dim CellString As String

'Get Selection Location and Size
RowStart = Selection.Row
ColStart = Selection.Column
ColCount = Selection.Columns.Count
RowCount = Selection.Rows.Count
RowEnd = RowStart + RowCount - 1
ColEnd = ColStart + ColCount - 1

'Get Indent String
IndentString = Sheet1.TextBoxIndentSpaces.Text

'Start Table
Sheet1.TextBoxOutput.Text = IndentString + ""

'Make Table Cells
For ctrRow = RowStart To RowEnd
Sheet1.TextBoxOutput.Text = Sheet1.TextBoxOutput.Text + vbCrLf + IndentString + " "
For ctrCol = ColStart To ColEnd
CellString = Sheet1.Cells(ctrRow, ctrCol).Text
Sheet1.TextBoxOutput.Text = Sheet1.TextBoxOutput.Text + vbCrLf + IndentString + " "
Next ctrCol
Sheet1.TextBoxOutput.Text = Sheet1.TextBoxOutput.Text + vbCrLf + IndentString + " "
Next ctrRow

'Close Table
Sheet1.TextBoxOutput.Text = Sheet1.TextBoxOutput.Text + vbCrLf + IndentString + "
" + CellString + "

<tbody>
</tbody>
"

End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

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