Excelsortingdynamic列表或使用VBA然后sorting

我正在使用工作表2将数据从工作表1中提取出来。

A9有这个公式:

=(INDEX(sheet1!$G$9:$G$7000,MATCH(0,INDEX(COUNTIF($A$8:A8,sheet1!$G$9:$G$7000),0,0),0)) 

(它看起来通过G列,并取出重复和空白)

B9有这个公式:

 =IF(MAX(IF($A9=sheet1!G:G,sheet1!E:E))=MIN(IF($A9=sheet1!G:G,sheet1!E:E)),"Only 1 Entry",MAX(IF($A9=sheet1!G:G,sheet1!E:E))-MIN(IF($A9=sheet1!G:G,sheet1!E:E))) 

(这一张在第2页的A列中查找,然后在Sheet1上查找date,最小值和最大值以确定某个项目的年份)

C9有这个公式:

 =SUMIF(sheet1!$G$9:$G$7000,A9,sheet1!$B$9:$B$7000) 

(这看起来像表2中的列A,并参考表1加起来小时)

问题是,如果我sorting列2上的列C没有任何变化。 我认为,因为它试图过滤它,dynamic公式将其重新排列回到表1中的内容。基本上不pipe你如何尝试和过滤它,列表都与基于sheet1的列表保持一致。 我甚至尝试对表1中的列进行sorting,以查看表单2是否会更改,但是由于表单2中C列中的数据实际上不存在于表单1上,因此无法工作。

我该如何过滤C列甚至B以及其他已经存在的dynamic公式?

我在网上searchfind一个解决scheme,但无法find任何可行的。 如果我不能使用这个dynamic列表,我想也许我可以使用VBA在A列表2中创build列表,并使列表成为静态列表。

我也search了一个VBA删除重复和空白,但由于某种原因,它提出了一个空白。 我发现一些做了一部分,但不是两个。

 Sub MakeUnique() Dim vaData As Variant Dim colUnique As Collection Dim aOutput() As Variant Dim i As Long 'Put the data in an array vaData = Sheet1.Range("A5:A7000").Value 'Create a new collection Set colUnique = New Collection 'Loop through the data For i = LBound(vaData, 1) To UBound(vaData, 1) 'Collections can't have duplicate keys, so try to 'add each item to the collection ignoring errors. 'Only unique items will be added On Error Resume Next colUnique.Add vaData(i, 1), CStr(vaData(i, 1)) On Error GoTo 0 Next i 'size an array to write out to the sheet ReDim aOutput(1 To colUnique.Count, 1 To 1) 'Loop through the collection and fill the output array For i = 1 To colUnique.Count aOutput(i, 1) = colUnique.Item(i) Next i 'Write the unique values to column B Sheet2.Range("A9").Resize(UBound(aOutput, 1), UBound(aOutput, 2)).Value = aOutput End Sub 

此VBA创build一个没有重复的列表,但留下空白…

那么,怎样才能将第2页上的B列和C列sorting,A列是从第1列中的数据派生的,没有重复和空白? 有没有一种方法来sorting和使用dynamic公式,或者应该用VBA来完成?

您的发布代码的这个版本将包括唯一列表中的空白:

 Sub MakeUnique() Dim vaData As Variant Dim colUnique As Collection Dim aOutput() As Variant Dim i As Long 'Put the data in an array vaData = Sheet1.Range("A5:A7000").Value 'Create a new collection Set colUnique = New Collection 'Loop through the data For i = LBound(vaData, 1) To UBound(vaData, 1) 'Collections can't have duplicate keys, so try to 'add each item to the collection ignoring errors. 'Only unique items will be added If vaData(i, 1) <> "" Then On Error Resume Next colUnique.Add vaData(i, 1), CStr(vaData(i, 1)) On Error GoTo 0 End If Next i 'size an array to write out to the sheet ReDim aOutput(1 To colUnique.Count, 1 To 1) 'Loop through the collection and fill the output array For i = 1 To colUnique.Count aOutput(i, 1) = colUnique.Item(i) Next i 'Write the unique values to column B Sheet2.Range("A9").Resize(UBound(aOutput, 1), UBound(aOutput, 2)).Value = aOutput End Sub