Results 1 to 2 of 2

Thread: AutoFilter Criteria Field in VBA

  1. #1

    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

    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