Table VBA code help for email

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,227
Office Version
  1. 2010
Platform
  1. Windows
Hi i hope you can help me please i have the table below which is a bit messy at moment as it is not alligned neatly as the bottom row is long than the 1st and 2nd row, i have tried amending but it caused an error, and i also want to add another line to the code but it says i have added to much, the new line i want to add is
Code:
"<th>Late Raises:</th>" & "<td>" & Worksheets("Handover").Range("F9").Value & "</td>" &
VBA Code:
   aEmail.htmlBody = "<html>" & _
                    "<p>Hi All, good afternoon,</p>" & _
                    "<p><u><b>" & Me.TextBox4.Value & "</p></u></b>" & _
                    "<table border=""1"", cellpadding=""18"", style=background:""#a6bbde"" >" & _
                "<tr>" & _
                    "<th>NCMO Issue:</th>" & "<td>" & Worksheets("Handover").Range("C5").Value & "</td>" & "<th>Re-Raised:</th>" & "<td>" & Worksheets("Handover").Range("F5").Value & "</td>" & _
                    "</tr>" & _
                "<tr>" & _
                    "<th>SNR:</th>" & "<td>" & Worksheets("Handover").Range("C6").Value & "</td>" & "<th>Additional Jobs:</th>" & "<td>" & Worksheets("Handover").Range("F6").Value & "</td>" & _
                    "</tr>" & _
                "<tr>" & _
                    "<th>Replans:</th>" & "<td>" & Worksheets("Handover").Range("C7").Value & "</td>" & "<th>Incorrectly Booked:</th>" & "<td>" & Worksheets("Handover").Range("F7").Value & "</td>" & "<th>IGT Issue:</th>" & "<td>" & Worksheets("Handover").Range("C9").Value & "</td>" & "<th>Outages:</th>" & "<td>" & Worksheets("Handover").Range("c8").Value & "</td>" & _
                    "</tr>" & _
                    "</table>" & _
                "" & _
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi i have managed to add the extra bit i want but the table is not looking nice, i have 2 tables on top row, 2 tables on 2nd row and 5 tables on last row, is there any way to put 3 tables on each row.
VBA Code:
    aEmail.htmlBody = "<html>" & _
                    "<p>Hi All, good afternoon,</p>" & _
                    "<p><u><b>" & Me.TextBox4.Value & "</p></u></b>" & _
                    "<table border=""1"", cellpadding=""18"", style=background:""#a6bbde"" >" & _
                "<tr>" & _
                    "<th>NCMO Issue:</th>" & "<td>" & Worksheets("Handover").Range("C5").Value & "</td>" & "<th>Re-Raised:</th>" & "<td>" & Worksheets("Handover").Range("F5").Value & "</td>" & _
                    "</tr>" & _
                "<tr>" & _
                    "<th>SNR:</th>" & "<td>" & Worksheets("Handover").Range("C6").Value & "</td>" & "<th>Additional Jobs:</th>" & "<td>" & Worksheets("Handover").Range("F6").Value & "</td>" & _
                    "</tr>" & _
                "<tr>" & _
                    "<th>Replans:</th>" & "<td>" & Worksheets("Handover").Range("C7").Value & "</td>" & "<th>Incorrectly Booked:</th>" & "<td>" & Worksheets("Handover").Range("F7").Value & "</td>" & "<th>IGT Issue:</th>" & "<td>" & Worksheets("Handover").Range("C9").Value & "</td>" & "<th>Outages:</th>" & "<td>" & Worksheets("Handover").Range("c8").Value & "</td>" & _
                    "<th>Late Raises:</th>" & "<td>" & Worksheets("Handover").Range("F9").Value & "</td>" & _
                    "</tr>" & _
                    "</table>" & _
 
Upvote 0
Hi,

Try this. Untested. Check for " or & missing if you find problems

HTML:
  aEmail.htmlBody = "<html>" & _
                    "<p>Hi All, good afternoon,</p>" _
                    & "<p><u><b>" & Me.TextBox4.Value & "</p></u></b>" _
                    & "<table border=1, cellpadding=18, style=background:#a6bbde >" _
                    & "<tr>" _
                    & "<th>NCMO Issue:</th>  <td>" & Worksheets(Handover).Range(C5).Value & "</td>" _
                    & "<th>Re-Raised:</th>  <td>" & Worksheets(Handover).Range(F5).Value & "</td>" _
                    & "<th>SNR:</th>  <td>" & Worksheets(Handover).Range(C6).Value & "</td>" _
                    & "</tr>" _
                    & "<tr>" _
                    & "<th>Additional Jobs:</th>  <td>" & Worksheets(Handover).Range(F6).Value & "</td>" _
                    & "<th>Replans:</th>  <td>" & Worksheets(Handover).Range(C7).Value & "</td>" _
                    & "<th>Incorrectly Booked:</th>  <td>" & Worksheets(Handover).Range(F7).Value & "</td>" _
                    & "</tr>" _
                    & "<tr>" _
                    & "<th>IGT Issue:</th>  <td>" & Worksheets(Handover).Range(C9).Value & "</td>" _
                    & "<th>Outages:</th>  <td>" & Worksheets(Handover).Range(c8).Value & "</td>" _
                    & "<th>Late Raises:</th>  <td>" & Worksheets(Handover).Range(F9).Value & "</td>" _
                    & "</tr>" _
                    & "</table></html>"
 
Upvote 0
Hi thank you for the code, but i get a syntax error and the whole code is turned yellow.
 
Upvote 0
Hi,

because I set it up as html first I had to remove all ", _ & characters.
I failed to put back the ones for the worksheet name and the cell.

I note C9 comes before C8. That might be a cut/paste error of the line.

HTML:
= "<html>" _
                    & "<p>Hi All, good afternoon,</p>" _
                    & "<p><u><b>" & Me.TextBox4.Value & "</p></u></b>" _
                    & "<table border=1, cellpadding=18, style=background:#a6bbde >" _
                    & "<tr>" _
                    & "<th>NCMO Issue:</th><td>" & Worksheets("Handover").Range("C5").Value & "</td>" _
                    & "<th>Re-Raised:</th><td>" & Worksheets("Handover").Range("F5").Value & "</td>" _
                    & "<th>SNR:</th><td>" & Worksheets("Handover").Range("C6").Value & "</td>" _
                    & "</tr>" _
                    & "<tr>" _
                    & "<th>Additional Jobs:</th><td>" & Worksheets("Handover").Range("F6").Value & "</td>" _
                    & "<th>Replans:</th><td>" & Worksheets("Handover").Range("C7").Value & "</td>" _
                    & "<th>Incorrectly Booked:</th><td>" & Worksheets("Handover").Range("F7").Value & "</td>" _
                    & "</tr>" _
                    & "<tr>" _
                    & "<th>IGT Issue:</th><td>" & Worksheets("Handover").Range("C9").Value & "</td>" _
                    & "<th>Outages:</th><td>" & Worksheets("Handover").Range("C8").Value & "</td>" _
                    & "<th>Late Raises:</th><td>" & Worksheets("Handover").Range("F9").Value & "</td>" _
                    & "</tr>" _
                    & "</table>" _
                    & "</html>"
 
Upvote 0
Hi would I be okay to use this new code? Or do I need to change something? Thankyou very much as well for your help.
 
Upvote 0
Yes. Just cut and paste to replace the previous block of code.
 
Upvote 0
Ok thankyou for your support and help. I shall try this on Tuesday:)
 
Upvote 0

Forum statistics

Threads
1,213,504
Messages
6,114,016
Members
448,543
Latest member
MartinLarkin

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