感谢回复,筛选后的表格是这样的应该不是没数据的问题,我代码贴下面麻烦帮我看下怎么改好一些,谢啦🙏
代码:
Sub 添加2()
Dim ws1, ws2, i, k, arr, kai
Dim rg, j
Set ws1 = ThisWorkbook.Worksheets("采购单")
Set ws2 = ThisWorkbook.Worksheets("开单")
Set kai = ws2.ListObjects("TB_开单")
With ws1.Range("a1").CurrentRegion
.AutoFilter
.AutoFilter field:=2, Criteria1:=ws2.Range("$Q$4")
.AutoFilter field:=3, Criteria1:=ws2.Range("$U$4")
End With
If ws1.FilterMode Then
With ws1.AutoFilter.Range.SpecialCells(xlCellTypeVisible) ’这句还是会报错...
For i = 1 To .Areas.Count
k = k + .Areas(i).Rows.Count
Next
End With
arr = Range("e2:i" & k)
End If
For i = 1 To UBound(arr) '表格插入多行
kai.ListRows.Add Position:=1, AlwaysInsert:=True
Next
End Sub