VBA Autofilter Cell(3).Value2

GlennL

New Member
Joined
Sep 25, 2018
Messages
37
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hello,

I am trying to get the value2 of the third row of column6 of a worksheet which has an autofilter applied.

I tried the code below, but I am getting the value of as if there is no autofilter.

Code:
Set rng = ws.AutoFilter.Range.columns(6).SpecialCells(xlCellTypeVisible).Cells(3)

Any suggestions?
 
Simplified per @RoryA's suggestion:
VBA Code:
Sub GetOccurenceOfVisibleCells_Mod()

Dim ws As Worksheet
Dim rngVis As Range
Dim rCell As Range
Dim iCell As Long, iTgtCell As Long
Dim rTgt As Range

Set ws = ActiveSheet

Set rngVis = ws.AutoFilter.Range.Columns(6).Offset(1).SpecialCells(xlCellTypeVisible)

iTgtCell = 3

For Each rCell In rngVis
    iCell = iCell + 1
    If iCell = iTgtCell Then
        Set rTgt = rCell
        Exit For
    End If
Next rCell

Debug.Print rTgt.Address, rTgt.Value

End Sub
 
Upvote 0
Solution

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Here's another option you could try (I don't know if there's a more direct way).
It work great thank you!
I was after the 3 data row after the header so I added the offset range
VBA Code:
AutoFilter.Range.Columns(6).Offset(1).SpecialCells(xlCellTypeVisible)
from @Alex Blakenburg
If I could add both of these as solutions I would.
 
Upvote 0
Your code only works because the column you are filtering on happens to have all the same values in contiguous blocks. Change F3 to 2, reapply the filter for 1, then try your code.
Well there's a trap for young players. Thanks very much for the explanation Rory.
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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