|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
我将代码贴上,同时也传上附件。。。要求是在表一里批量输入单号及入库数量,执行程序后先判断表二中入库数量与出库数量列是否为空,如果为空则直接将单号与入库数量填入相应的行,如果不为空则另一行填入相应的数据。。。。出库程序也是一样。。。多谢大虾指点。。。我写的代码能正确执行,可是感觉速度低,因为执行了好多循环与嵌套。。。。有没有高手可以用数组的方法提高效率??????或者别的方法,只要能提高速度就行。。。
Sub 入库修改后()
Dim a, b, c, d As Integer
Dim bb, cc, dd As String
Dim a1, b1 As Range
a = Sheets(1).Cells(65000, 11).End(xlUp).Row '判断总行数
Worksheets(1).Activate
Application.ScreenUpdating = False
For b = 2 To a '每行都判断
If Cells(b, 11) <> "" Then
aa = Cells(b, 2)
c = Sheets(2).Range("B:B").Cells.Find(aa).Row
ff = "=countif(进出库明细表!B:B,""" & aa & """)"
Cells(1, 13).Formula = ff
d = Cells(1, 13).Value
If Sheets(2).Cells(c, 7) = "" And Sheets(2).Cells(c, 9) = "" Then
Sheets(2).Cells(c, 8) = Cells(b, 10)
Sheets(2).Cells(c, 9) = Cells(b, 11)
Sheets(2).Cells(c, 5) = Date
Else
Sheets(2).Rows(c + d).Insert
Sheet2.Range(Sheet2.Cells(c + d, 1), Sheet2.Cells(c + d, 4)).Value = Sheet2.Range(Sheet2.Cells(c, 1), Sheet2.Cells(c, 4)).Value
Sheets(2).Cells(c + d, 8) = Cells(b, 10)
Sheets(2).Cells(c + d, 5) = Date
Sheets(2).Cells(c + d, 9) = Cells(b, 11)
End If
End If
Next b
f = 2
Do While Sheets(2).Cells(f, 1) <> ""
Sheets(2).Cells(f, 1) = f - 1
f = f + 1
Loop
Range("J2:K65000").Clear
Application.ScreenUpdating = True
End Sub |
|