Excel添加行,继续

我创build了一个引用工作簿。 每个产品有8张表格,数量/描述/单位/总计,我们在每张表格上build立一个产品select,把我们需要的物品的数量放在一栏。

我想创build一个Main表,只有当数量不是0时,才会拉出其他表上的项目。我创build了基本公式,这样如果数量为0,这一行是空白的,如果不是,则填充适当的数据,但这里是我卡住的地方。

基本上我希望Main sheet能够像通过公式一样,但是要继续沿着表格移动,然后转到下一个表格(下一页)并继续。 我也喜欢它没有任何空行。 这可能吗?

当前代码:

 Sub delblankrows() Dim s1 As Worksheet Dim tmpR As Range Dim rowcount As Long, colcount As Long, i As Long, j As Long, k As Boolean Set s1 = Sheets("Complete") Set tmpR = s1.UsedRange rowcount = tmpR.Rows.Count colcount = tmpR.Columns.Count For i = rowcount To 1 Step -1 k = 0 For j = 1 To colcount If tmpR.Value2(i, j) <> "" Then k = 1 Exit For End If Next j End Sub 

如果你所要做的只是从非空白或非零数量的其他工作表中抽取行(单元格值而不是公式),假设列为“A”,那么下面的行那。 但从你的问题陈述你可能会做一些除此之外。 此代码假定每个工作表上都有一个标题行,并且数据从第2行开始。它还假定您只有列“A”到“D”的数据:

 Option Explicit Sub AddRowContinueOn() Dim ws As Worksheet, cws As Worksheet Dim cLRow As Integer, sLRow As Integer Set cws = Worksheets("Complete") cLRow = cws.Cells(cws.Rows.Count, "A").End(xlUp).row + 1 Dim i As Integer, val As Integer For Each ws In ActiveWorkbook.Worksheets If ws.Name <> "Complete" Then sLRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).row For i = 2 To sLRow val = CInt(ws.Cells(i, "A").Value) If val <> 0 Then cws.Range("A" & cLRow & ":D" & cLRow).Value = ws.Range("A" & i & ":D" & i).Value cLRow = cLRow + 1 End If Next End If Next End Sub