过滤后如何处理没有值

这是我的数据库: 这是我的数据库

现在,这是我的工作表“产品”:

在这里输入图像说明

而这个我的表“文章”:

在这里输入图像说明

我有这样的代码,实际工作:

' Extract Products ReDim Preserve aProducts(2 * .Rows.Count) lRow = 1 sCriteria = "Produit" aProducts(lRow) = Array("Id Product", "Value A", "Value B", "Value C") aHdr = Array("Id product", "Value A", "Value B", "Value C", _ "Type of value A", "Type of value B", "Type of Value C") GoSub Get_Field_Post ' Extract Products - Value A b = aPos(5) .AutoFilter Field:=b, Criteria1:=sCriteria For Each vItm In .Offset(1, 0).Resize(-1 + .Rows.Count) _ .SpecialCells(xlCellTypeVisible).Rows With vItm lRow = 1 + lRow aProducts(lRow) = Array(.Cells(aPos(1)).Value2, _ .Cells(aPos(2)).Value2, Empty, Empty) End With Next .AutoFilter Field:=b 

整个代码有点长,这就是为什么我添加一个文件,随时下载它来了解整个代码。

除了有一个完整的(除了标题)空列之外,它完美的工作:

在这里输入图像说明

一些帮助将是一个好消息。

链接下载文件: https : //drive.google.com/file/d/0B5DpGwPWsIfbUjlueHBjTU50Mzg/view?usp=sharing

你可以这样去(见注释行):

 .AutoFilter Field:=b, Criteria1:=sCriteria If Application.WorksheetFunction.Subtotal(103, .Resize(, 1)) > 1 Then '<--| check if any cell filtered other than header For Each vItm In .Offset(1, 0).Resize(-1 + .Rows.COUNT) _ .SpecialCells(xlCellTypeVisible).Rows With vItm lRow = 1 + lRow aProducts(lRow) = Array(.Cells(aPos(1)).Value2, _ .Cells(aPos(2)).Value2, Empty, Empty) End With Next End If