来自过滤数据的名称范围分配

时间:2018-08-09 19:49:19

标签: excel range

我遇到了问题。我试图将ListBox行源分配给已过滤的范围。我可以将复制的范围复制到新的工作表中,然后再为该范围分配一个名称,但是我不想为此创建额外的工作表。这是我的代码。这不是完美的,因为我不是专业程序员,但这使我发疯。一切正常,只是未将过滤范围分配给范围名称。

      If pairfilter.Value <> "" Then

         ' APPLY FILTER TO CURRENCY PAIR
         .Range("G2").AutoFilter Field:=7, Criteria1:=pairfilter.Value, VisibleDropDown:=True

      End If

      If wlbfilter.Value <> "" Then

         ' APPLY FILTER TO WIN-LOSS-BREAKEVEN
         .Range("Y2").AutoFilter Field:=25, Criteria1:=wlbfilter.Value, VisibleDropDown:=True

      End If

      If lsfilter.Value <> "" Then

          ' APPLY FILTER TO LONG-SHORT
          .Range("D2").AutoFilter Field:=4, Criteria1:=lsfilter.Value, VisibleDropDown:=True

      End If

      If signalfilter.Value <> "" Then

          ' APPLY FILTER TO SIGNALS
          .Range("AD2").AutoFilter Field:=30, Criteria1:=signalfilter.Value, VisibleDropDown:=True

      End If

      If structurefilter.Value <> "" Then

          ' APPLY FILTER TO STRUCTURE
          .Range("AE2").AutoFilter Field:=31, Criteria1:=structurefilter.Value, VisibleDropDown:=True

      End If

      ActiveSheet.AutoFilter.ApplyFilter

       lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
       Set ws = Sheets(2)
       ws.Activate
       With ws
       Range("A1", Range("AH" & .Rows.Count).End(xlUp)).Name = "Dynamic1"
       Me.tradelist.RowSource = "Dynamic1"
       Me.tradelist.ListIndex = 1
       TabStrip1.Value = 0
      End With

0 个答案:

没有答案