Results 1 to 2 of 2

AutoFilter Criteria Field in VBA

This is a discussion on AutoFilter Criteria Field in VBA within the Excel Questions forums, part of the Question Forums category; I've recording an autofilter macro, then trying to add additional code in VBA . I'm trying to set the 'criteria' ...

  1. #1
    New Member
    Join Date
    Jun 2002
    Posts
    3

    Default

    I've recording an autofilter macro, then trying to add additional code in VBA. I'm trying to set the 'criteria' field to a data value - see following code - but VBA gives an error. Is there any way to force the criteria field to be want you want it to without hard-coding values??

    Dim CostCenter As String
    Selection.AutoFilter Field:=1, criteria1:= CostCenter

  2. #2

    Join Date
    May 2002
    Posts
    16

    Default

    You have to assign a value to Cost Center.

    Or, if CostCenter is a named range, it does not have to be "dimmed" and the code would be :-

    Selection.AutoFilter Field:=1, Criteria1:=Range("CostCenter")

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com