我把你其他部分都删除了,只保留了相应的部分,你看看里面的代码,自己学习,掌握了就可以自己改
y6weq8Y6.rar
(45.39 KB, 下载次数: 161)
由于数据有2000行,判断较多,运行时间约为2秒,代码如下:
Private Sub CommandButton1_Click()
Dim arr
Dim arr1()
Dim irow%, i%
Dim a, b
Dim atime
Dim c As Range
atime = Timer
Application.ScreenUpdating = False '关闭屏幕更新,防止闪屏及加快代码速度
irow = [a65536].End(xlUp).Row '计算A列非空得最后一行
arr = Range("a3:b" & irow) '把单元格赋值给数组
ReDim arr1(1 To irow - 2, 1 To 11)
For i = 1 To irow - 2
a = Split(arr(i, 1), "-") '参考split函数哦
b = Split(a(0), "/")
arr1(i, 1) = b(0)
arr1(i, 2) = b(1)
arr1(i, 3) = b(2)
arr1(i, 4) = a(1)
arr1(i, 5) = IIf(UBound(a) > 1, a(UBound(a)), "") '前1~5列来自第一列单元格
Set c = Sheets("在线批号").Columns(1).Find(arr(i, 2), lookat:=xlWhole)
If Not c Is Nothing Then
arr1(i, 6) = c.Offset(0, 1) '第6列是根据批号来查找的
End If
arr1(i, 7) = Switch(arr1(i, 3) = 0, -1, arr1(i, 3) < 50, 1, arr1(i, 3) >= 50, 0) '第7列
If arr1(i, 4) = 0 Then '第8列的计算过程
arr1(i, 8) = -1
ElseIf (arr1(i, 3) / arr1(i, 4)) < (167 / 144) Then
arr1(i, 8) = 1
Else
arr1(i, 8) = 0
End If
arr1(i, 9) = IIf(arr1(i, 1) = "W", 1, 0) '第9列的计算过程
Set c = Sheets("在线批号").Columns(6).Find(arr1(i, 2), lookat:=xlWhole)
If Not c Is Nothing Then
arr1(i, 11) = c.Offset(0, 1) '第11列是根据纱种来查找的
End If
If arr1(i, 11) >= 1 Then
arr1(i, 10) = 2
ElseIf arr1(i, 11) < 0 Then
arr1(i, 10) = -1
ElseIf (arr1(i, 7) + arr1(i, 8)) > 0 Then
arr1(i, 10) = 1
Else
arr1(i, 10) = 0 '第10列的计算过程
End If
Next
Range("e3").Resize(irow - 2, 11) = arr1 '把数组赋值给单元格
Application.ScreenUpdating = True
MsgBox "Already Done!Total:=" & Format(Timer - atime, "0.00") & "s" '记录运算的时间
End Sub
|