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

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).
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,224,826
Messages
6,181,192
Members
453,021
Latest member
pingpong7117

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