Consulting

Results 1 to 5 of 5

Thread: Filter and name the rows when available

  1. #1

    Filter and name the rows when available

    Hi all ,

    I have this code that does a simple job . only when criteria is met if not . it is going astray .

    For example : below code filter column (K) " DA,DB,DZ" and put a a comment in adjacent column ("S") " Deduction". so far so good . But code is changing first cell of column ("S") even though documnt type (DA,DB,DZ) misses.


    Sub filter_deduction()
    
    Range("K1:K" & Range("K" & Rows.Count).End(3).Row).AutoFilter 1, Criteria1:=Array("DA", "DB", "DZ"), Operator:=xlFilterValues
            
    Range("S2:S" & Range("K" & Rows.Count).End(3).Row).SpecialCells(12).Formula = "Deductions"
    
    
    ActiveSheet.AutoFilterMode = False
    End Sub
    Attached Files Attached Files

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    on error resume next

  3. #3
    Hi mana.


    i already tried that . unfortunately i still comment in first cell .

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    Sub filter_deduction()
    ActiveSheet.AutoFilterMode = False
    lr = Range("K" & Rows.Count).End(3).Row
    Range("K1:K" & lr).AutoFilter 1, Criteria1:=Array("DA", "DB", "DZ"), Operator:=xlFilterValues
    On Error Resume Next
    Range("S2:S" & lr).SpecialCells(12).Value = "Deductions"
    On Error GoTo 0
    ActiveSheet.AutoFilterMode = False
    End Sub
    Important changes highlighted below in red:

    Sub filter_deduction()
    ActiveSheet.AutoFilterMode = False
    lr = Range("K" & Rows.Count).End(3).Row

    Range("K1:K" & lr).AutoFilter 1, Criteria1:=Array("DA", "DB", "DZ"), Operator:=xlFilterValues
    On Error Resume Next
    Range("S2:S" & lr).SpecialCells(12).Value = "Deductions"
    On Error GoTo 0
    ActiveSheet.AutoFilterMode = False
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    Perfect . i got it now. thanks mate ... with your help i was able to do beginner level VBA ..i am really indebted to you .

Posting Permissions

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