dcsimg
Results 1 to 5 of 5

Thread: Autofilter the visible range only

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2018
    Posts
    314

    Autofilter the visible range only

    Hi
    I need to perform filtering on two columns usign VBA. The first filtering should give me the docuemnt number and the second filtering should give the highest version for that document number.

    My code is here:

    Code:
    For K = 0 To UBound(DMSCCNR) - 1
     SourceWorkBook.Worksheets(MyWSheets.Name).Range("A2:H" & TRowsSourceFile).AutoFilter Field:=1, _
     Criteria1:=DMSCCNR(K), Operator:=xlFilterValues  'column 1/A is the document number
     SourceWorkBook.Worksheets(MyWSheets.Name).Range("A2:H" & TRowsSourceFile).SpecialCells(xlCellTypeVisible).AutoFilter Field:=3, _
     Criteria1:="1", Operator:=xlTop10Items 'column 3/C is the version number
    
    Next K
    It gives me the higest version that exist in that column but not for the visible range.

    Any help is Appreciated.
    Thanks.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,448

    Re: Autofilter the visible range only

    you could try like
    Code:
    SourceWorkBook.Worksheets(MyWSheets.Name).Range("A2:H" & TRowsSourceFile).SpecialCells(xlCellTypeVisible).AutoFilter...............................
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2018
    Posts
    314

    Re: Autofilter the visible range only

    Isn't it what I am doing?
    Code:
    SourceWorkBook.Worksheets(MyWSheets.Name).Range("A2:H" & TRowsSourceFile).SpecialCells(xlCellTypeVisible).AutoFilter Field:=3, _
     Criteria1:="1", Operator:=xlTop10Items 'column 3/C is the version number

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,448

    Re: Autofilter the visible range only

    do you have rows that are hidden?, or are you referring to rows on the current visible area of the worksheet?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,327

    Re: Autofilter the visible range only

    Moved to Office Dev
    You can depend upon the Americans to do the right thing. But only after they have exhausted every other possibility - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width