Excel VBA按列和列单元格值进行筛选

时间:2017-03-16 15:28:24

标签: excel vba excel-vba

我有以下代码并且它一直给出错误"未找到命名参数"当试图做下面的事情时。

所需行为:对于活动工作簿中的所有工作表循环并执行以下操作;居中对齐,自动调整行,自动调整列,然后对名为&#34的列进行排序;分配给"按价值"杰克"然后过滤" date"从最古老到最新。 具体问题:每当我到达排序部分时出错

如果能够:我还想删除基于列名的重复项,而不仅仅是下面我在下面的部分中删除重复项,这会像更改" 36"那样简单。成为名称" ID" ?

    Sub Filter_NOW()
    '
    ' Filter Macro
    '
    ' Declaration
      Dim wkSt As String
      Dim wkBk As Worksheet
      Dim temp As Variant
      Dim lastCol As Long
      Dim FilterCol As Variant
      Dim FilterColB As Variant

      wkSt = ActiveSheet.Name
' This Loops Through All Sheets
      For Each wkBk In ActiveWorkbook.Worksheets
          wkBk.Activate
          lastCol = wkBk.Cells(1, Columns.Count).End(xlToLeft).Column
          FilterCol = wkBk.Rows(1).Find("Assigned to")
          FilterColB = wkBk.Rows(1).Find("Date")

'This is to center align all rows
          wkBk.Rows.HorizontalAlignment = xlCenter
' Resize Columns
          wkBk.Columns.EntireColumn.AutoFit
' Resize Rows
          wkBk.Rows.EntireRow.AutoFit
' Filter by Column Name and Value
          wkBk.Range("$A:$BB").AutoFilter Field:=FilterCol, Criteria1:="JACK"
' Filter by Column Name and Value
          wkBk.Range("$A:$BB").AutoFilter Field:=FilterColB, SortOn:=xlSortOnValues, Order:=xlDescending
' Remove Duplicates
     wkBk.Range("$A$1:$AM$373").RemoveDuplicates Columns:=36, Header:= _
        xlYes
      Next wkBk
      Sheets(wkSt).Select
    End Sub

0 个答案:

没有答案