根据实际单元格地址过滤列

时间:2016-04-07 14:25:11

标签: excel vba excel-vba filter

我搜索了大量网站但没有找到任何网站。请帮忙。

我是VBA的新手,有些东西我不能只记录在Macro Recorder中。

这是我的问题:

我有一张参考,过滤的列A包含另一张名为Target的工作表实际单元格地址(例如A5包含F1,A6包含F2等)。

我需要:

  1. 我需要一个按钮来根据参考表中的A列过滤目标表。
  2. 我需要突出显示目标表中过滤的单元格。
  3. 注意:

      

    目标表中只有F列需要过滤。

         

    参考表中的B列被过滤,这意味着,A列也被过滤了。

    Check this image to see what I'm trying to imply

    这是过滤B的代码。我只需要将那些过滤后的单元格的相应值添加到A列(这是Target列中单元格的实际地址)

    Sub RefreshFilter()
    '
    ' a Macro
    
        'Unfilter if data in sheet is filtered.
        ActiveSheet.ListObjects("Data").AutoFilter.ShowAllData
    
        'Refresh Data
        ActiveWorkbook.RefreshAll
    
       'Filter Row B with RED fill
        ActiveSheet.ListObjects("Data").Range.AutoFilter Field:=1, Criteria1:=RGB( _
            255, 0, 0), Operator:=xlFilterCellColor
    End Sub
    

    Here's the actual

2 个答案:

答案 0 :(得分:0)

在B列过滤器后单独使用此代码。

Sub changecolor_Final()
    Dim cl As Range
    Dim r As Range
    lastfilterrow = Range("A" & Rows.Count).End(xlUp).Row
    Set r = Range("A5:A" & lastfilterrow)
    For Each cl In r.SpecialCells(xlCellTypeVisible)
        With Worksheets("Target")
            .Range(cl).Interior.ColorIndex = 6
        End With
    Next
End Sub

答案 1 :(得分:0)

dim metabasePath as String = "IIS://localhost/W3svc/1"
Private Sub SetProperty(ByVal metabasePath As String, ByVal propertyName As String, ByVal newValue As Object, clearCurrentValue As Boolean)
        Dim path As DirectoryEntry
        path = New DirectoryEntry(metabasePath)
        If clearCurrentValue Then path.Properties(propertyName).Clear()
        path.Properties(propertyName).Add(newValue)
        path.CommitChanges()
End Sub
相关问题