Hi, I need some help with the below - I have a spreadsheet which contains a filter and "rng=.SpecialCells(xlCellTypeVisible)". For example, it will always copy from range A17 to G25". I wish for it to start from B17 and end at the last G cell of the filter. Can anyone enlighten me on how to achieve this? Thanks.
Code:
Set Cws = Worksheets.Add
FilterRange.Columns(FieldNum).AdvancedFilter _
Action:=xlFilterCopy, _
CopyToRange:=Cws.Range("A1"), _
CriteriaRange:="", Unique:=True
'Count of the unique values + the header cell
Rcount = Application.WorksheetFunction.CountA(Cws.Columns(1))
'If there are unique values start the loop
If Rcount >= 2 Then
For Rnum = 2 To Rcount
'Filter the FilterRange on the FieldNum column
FilterRange.AutoFilter Field:=FieldNum, _
Criteria1:=Cws.Cells(Rnum, 1).Value
'Look for the mail address in the MailInfo worksheet
mailAddress = ""
On Error Resume Next
mailAddress = Application.WorksheetFunction. _
VLookup(Cws.Cells(Rnum, 1).Value, _
Worksheets("Mailinfo").Range("A1:C" & _
Worksheets("Mailinfo").Rows.Count), 3, False)
On Error GoTo 0
clientAddress = Application.WorksheetFunction. _
VLookup(Cws.Cells(Rnum, 1).Value, _
Worksheets("Mailinfo").Range("A1:B" & _
Worksheets("Mailinfo").Rows.Count), 1, False)
If mailAddress <> "" Then
With Ash.AutoFilter.Range
On Error Resume Next
[COLOR=#ff0000][FONT=arial black] Set rng = .SpecialCells(xlCellTypeVisible)[/FONT][/COLOR]
On Error GoTo 0
End With
Set OutMail = OutApp.CreateItem(0)
Last edited by a moderator: