A little help with looping please

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
726
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
 
Glad to help and thanks for letting us know (y)
 
Upvote 0

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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