在EXCEL中的一列使用filter功能,我在一个窗体中添加一个combobox,我想把filter中的那些分类项读取出来赋值给combobox的list,怎么做?

解决方案 »

  1.   

    If ActiveSheet.AutoFilterMode = False Then
        MsgBox "The sheet does not have an AutoFilter"
        Exit Sub
      End If  'Get the sheet's AutoFilter object
      Set oAF = ActiveSheet.AutoFilter  'Loop through the Filters of the AutoFilter
      For i = 1 To oAF.Filters.Count    Dim j As Integer, ret()   ret = oAF.Range.FormulaR1C1Local
        For j = 1 To oAF.Range.Count
            MsgBox ret(j, 1)
        Next  Next
      

  2.   

    ret = oAF.Range.FormulaR1C1 也是一样的~
      

  3.   

    那如果我的表里有多个列使用了autofilter呢,我要把每个都取出来赋给不同的combobox,那怎么取啊。yinweihong的方式只适用于只有一个列使用了filter的情况吧?
      

  4.   

    Sub Macro1()
    If ActiveSheet.AutoFilterMode = False Then
        MsgBox "The sheet does not have an AutoFilter"
        Exit Sub
      End If  'Get the sheet's AutoFilter object
      Set oAF = ActiveSheet.AutoFilter  'Loop through the Filters of the AutoFilter
          Dim j As Integer, ret()   ret = oAF.Range.FormulaR1C1Local
       For i = 1 To oAF.Filters.Count
        For j = 1 To oAF.Range.Count / oAF.Filters.Count
        
            MsgBox ret(j, i)
        Next  Next
    End Sub
    别人给出来一些代码,要学会融会贯通~
      

  5.   

    Sub Macro1()
    If ActiveSheet.AutoFilterMode = False Then
        MsgBox "The sheet does not have an AutoFilter"
        Exit Sub
      End If  'Get the sheet's AutoFilter object
      Set oAF = ActiveSheet.AutoFilter  'Loop through the Filters of the AutoFilter
          Dim j As Integer, ret()   ret = oAF.Range.FormulaR1C1Local
       For i = 1 To oAF.Filters.Count
        For j = 1 To oAF.Range.Count / oAF.Filters.Count
        
            MsgBox ret(j, i)
        Next  Next
    End Sub
      

  6.   

    Sub Macro1()
    If ActiveSheet.AutoFilterMode = False Then
        MsgBox "The sheet does not have an AutoFilter"
        Exit Sub
      End If  'Get the sheet's AutoFilter object
      Set oAF = ActiveSheet.AutoFilter  'Loop through the Filters of the AutoFilter
          Dim j As Integer, ret()   ret = oAF.Range.FormulaR1C1Local
       For i = 1 To oAF.Filters.Count
        For j = 1 To oAF.Range.Count / oAF.Filters.Count
        
            MsgBox ret(j, i)
        Next  Next
    End Sub我这边提交咋老出错~?