Alternative for .SpecialCells(xlCellTypeVisible)

bluenceo

New Member
Joined
Sep 12, 2011
Messages
5
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:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
What exactly are you looking for an 'alternative' to?
 
Upvote 0
For example, to change it into ".Range("B17", .Range("GXX").End(xlUp))". However, G cell is dynamic and will change accordingly to the filter within the macro.
 
Upvote 0
What do you want to change to ".Range("B17", .Range("GXX").End(xlUp))"?

The range being filtered?
 
Upvote 0
The last visible row in column G might change because of the filter but the last row of data in column G won't.
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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