Copy table to email error

2000km12

New Member
Joined
Apr 19, 2023
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hello, I am attempting to copy part of my excel worksheet as a table to an email. I have a for loop that loops through every row, with "rw" being the variable used for that current row. When I use my code, it is only copying column G and I am unsure why.

Help would be appreciated

'Set the variables for the loop
Dim LastRw As Long, FirstRw As Long
Dim Rw As Long
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object

Set rng = Nothing
On Error Resume Next
'Only the visible cells in the selection
Set rng = Selection.SpecialCells(xlCellTypeVisible)

With ActiveSheet
'Define First and Last Rows
FirstRw = 2
LastRw = sht.UsedRange.Rows(.UsedRange.Rows.Count).Row

'Create loop to go through all rows
For Rw = LastRw To FirstRw Step -1

'If the due date is equal to today, run code:
If sht.Range("G" & Rw).Value = Date Then
Set rng = sht.Range("A:G" & Rw).SpecialCells(xlCellTypeVisible)

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

With OutMail
.Subject = "Reminder - CAR(s) Due Today"
.To = sht.Range("B" & Rw).Value
.CC = "Anna Passaro"

.HTMLBody = RangetoHTML(rng) & "Good Morning," & "<br>" & "<br>" & "This is a friendly reminder that you have a Corrective Action" & "<b>" _
& " due today." & "</b>" & " Please let me or Anna Passaro know if you require any additional support. " & "<br>" & "<br>" _
& "<u>" & "Please note, an extension cannot be requested as we are past the extension request due date. This action must be" & _
" completed today to avoid escalation." & "</u>" & "<br>" & "<br>" & "<br>" & "<br>" & "Thank You," & "<br>"

.Display
End With

Set OutApp = Nothing
Set Message = Nothing
End If
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Your On Error Resume Next is hiding the fact that the line below in invalid.
Rich (BB code):
Set rng = sht.Range("A:G" & Rw).SpecialCells(xlCellTypeVisible)

You need a row number after "A".
eg sht.Range("A2:G" & Rw)
 
Upvote 1
Solution

Forum statistics

Threads
1,214,520
Messages
6,120,016
Members
448,936
Latest member
almerpogi

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