VBA Autofilter same sheet twice / Email results

johnkrenkel

New Member
Joined
Apr 2, 2019
Messages
11
I am working on sending an email report using autofilter ranges. This code works great if only sending the rngNIM but if i try to add rngError, It breaks. I am guessing it has something with storing copied cells in the same filtered worksheet. Is there a way to do this?




VBA Code:
VBA Code:
With wsNIM
.AutoFilterMode = False
With rngNIM
.AutoFilter Field:=8, Criteria1:="<>"
.SpecialCells(xlCellTypeVisible).Copy
End With
End With

With wsNIM
.AutoFilterMode = False
With rngError
.AutoFilter Field:=7, Criteria1:="<>"
.SpecialCells(xlCellTypeVisible).Copy
End With
End With

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

On Error Resume Next
With OutMail
'.To = ""
.CC = "[EMAIL]me@me.com[/EMAIL]"
'.BCC = ""
.Subject = "subjectlinehere"
.HTMLBody = RangetoHTML(PCReconcilement) & vbNewLine & "Not in Master Record" & vbNewLine & RangetoHTML(rngNIM) & "Processing Error" & vbNewLine & RangetoHTML(rngError)
'You can add a file like this
'.Attachments.Add
.Send 'or use .Display
End With
On Error GoTo 0

How do I autofilter a second time and add to the body? FYI: RangeToHTML is a function
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
If you need it as a range, PasteSpecial it somwhere else and use that. Otherwise copy the values in an array and loop over the values. Unfortunately VBA.Join() doesn't help here.
VBA Code:
' Do the AutoFilter first.
Dim arrNIM() As Variant
arrNIM = rngNIM.SpecialCells(xlCellTypeVisible).Value2
and so on...
 
Upvote 0
If you need it as a range, PasteSpecial it somwhere else and use that. Otherwise copy the values in an array and loop over the values. Unfortunately VBA.Join() doesn't help here.
VBA Code:
' Do the AutoFilter first.
Dim arrNIM() As Variant
arrNIM = rngNIM.SpecialCells(xlCellTypeVisible).Value2
and so on...
Thank you, I was just looking into Arrays so adding something new to my growing skills :)
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,093
Latest member
dbomb1414

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