Insert parameters to existing code

Hlbet21

New Member
Joined
Dec 31, 2020
Messages
11
Office Version
  1. 2016
Platform
  1. Windows
I have set of parameters ( if then statements - to exclude certain rows) that I need to add to this code before it makes/saves the attachment. Where would be the best place to set them in the code? I’m absolutely stuck on this.

VBA Code:
Option Explicit
Sub sintek()
Dim Data, Dict As Object, Path As String, File As String, i As Long
Set Dict = CreateObject("Scripting.Dictionary")
Path = ThisWorkbook.Path: Sheets.Add.Name = "Temp"
With Sheets("Sheet1").ListObjects(1).Range
    Data = .Value
    For i = 2 To UBound(Data, 1)
        If Not Dict.exists(Data(i, 4)) Then
            File = Path & "\" & Data(i, 4)
            Dict.Add Data(i, 4), 1
            .AutoFilter 4, Data(i, 4)
            .SpecialCells(12).Copy Sheets("Temp").Range("A1")
            .AutoFilter
            With Sheets("Temp")
                .Columns.AutoFit
                .Copy
                ActiveWorkbook.SaveAs File & ".xlsx", 51
                ActiveWorkbook.Close saveChanges:=False
                .UsedRange.Delete
            End With
            With CreateObject("Outlook.Application").CreateItem(0)
                .Display
                .To = Data(i, 12)
                .Subject = "Whatever"
                .Body = "Whatever you want to say"
                .Attachments.Add File & ".xlsx"
                '.Send
                .Display
                Kill File & ".xlsx"
            End With
        End If
    Next i
End With
Application.DisplayAlerts = False: Sheets("Temp").Delete: Application.DisplayAlerts = True
End Sub
 
Last edited by a moderator:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I would put it after copying.

VBA Code:
  With Sheets("Temp")
                .Columns.AutoFit
                .Copy
                ***here***
 
Upvote 0

Forum statistics

Threads
1,215,676
Messages
6,126,173
Members
449,296
Latest member
tinneytwin

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