A little help with looping please

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
564
Office Version
  1. 2016
Platform
  1. Windows
I would like to loop through last row starting at A2.

Here is what I have so far:

VBA Code:
Sub Mail_test()
    
    Dim OutApp As Object
    Dim OutMail As Object
    Dim LR As Long
    Dim x As Long
    
    test_top = "<html><head><title></title></head><body>" _
        & "<style> table.main {border:2px solid black} " _
        & "<style> table.schedule {border-collapse:collapse;border:1px solid black;} " _
        & "<style> table.schedule td {border-collapse:collapse;border:1px solid black;} " _
        & "<style> .href { font-size: 13px; font-family: calibri;}</style> " _
        & "<table class=mainwidth:600px""><tr>" _
        & "<center><spanfont-size:19px;"">" _
        & "TITLE<br></span></center><br>" _
        & "<spanfont-size:15px;"">" _
        & "Text" _
        & "<center><table class=""schedule""width:590px;""><tbodyfont-size:13px;"">" _
        & "<tr align=""center"";style=""color:#c00000;"">" _
        & "<td>header</td><td>header</td><td>header</td><td>header</td></tr>" _

    test_bottom = "</tbody></table></center>" _
        & "Text</table></body></html>" & .HTMLBody
    
    LR = Cells(Rows.Count, 1).End(xlUp).Row
    
    For x = 2 To LR

    row = & "<tr><td>" & Range("A" & x) & "</td><td>text</td><td>text</td><td align=""center"">text</td></tr>" _

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    
    With OutMail
    
    .Display
        
    .HTMLBody = test_top & row (looping to LR in column A starting at A2) & test_bottom
    
    End With
        
    Set OutMail = Nothing
    Set OutApp = Nothing

End Sub
 

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
2,769
Office Version
  1. 2013
Platform
  1. Windows
Glad to help and thanks for letting us know (y)
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,395
Messages
5,837,015
Members
430,465
Latest member
Mackbay

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
Top