Consulting

Results 1 to 3 of 3

Thread: Solved: How do we test for a filtered row in vba

  1. #1
    VBAX Regular
    Joined
    Jun 2005
    Location
    Sydney
    Posts
    60
    Location

    Solved: How do we test for a filtered row in vba

    I do a lot of work with filters and would like to run macros where I highlight something I have filtered and run a "for each" loop against each cell in the highlighted area. This works well except that when some rows are hidden by the filter and they are included in the range, then the macro is applied to them as well. Does anyone have any ideas about how I can test for this. Here is a sample code that I use.

    Sub calcrange()
    TargetRange = Selection.Address

    For Each cell In Range(TargetRange)
    cell.Calculate
    Next
    End Sub

  2. #2
    Hi

    how about

    [vba]
    Sub calcrange()
    set TargetRange = Selection.SpecialCells(xlCellTypeVisible)

    For Each ce In TargetRange
    cell.Calculate
    Next TargetRange
    End Sub
    [/vba]


    Tony

  3. #3
    VBAX Regular
    Joined
    Jun 2005
    Location
    Sydney
    Posts
    60
    Location
    Thanks, that was perfect. Will save me minutes!!! but often.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •