LZ 按钮1的代码换成下面,运行时间只有2秒,快10秒: Private Sub CommandButton1_Click() Dim a%, b%, c%, d%, e%, n% Dim V() Application.ScreenUpdating = False t1 = Time() a = Range("a1").End(xlDown).Row - 1 b = Range("b1").End(xlDown).Row - 1 c = Range("c1").End(xlDown).Row - 1 d = Range("d1").End(xlDown).Row - 1 e = Range("e1").End(xlDown).Row - 1 n = a * b * c * d * e ReDim V(1 To n, 1 To 5) For k = 1 To n V(k, 1) = Cells(Int(k / (b * c * d * e)) + 2, 1) V(k, 2) = Cells(Int(k / (c * d * e) Mod b) + 2, 2) V(k, 3) = Cells(Int(k / (d * e) Mod c) + 2, 3) V(k, 4) = Cells((Int(k / e) Mod d) + 2, 4) V(k, 5) = Cells((k Mod e) + 2, 5) Next Sheet2.Rows("2:" & Sheet2.Range("A" & Cells.Rows.Count).End(xlUp)).ClearContents Sheet2.Range("a2" & ":e" & n + 1).Value = V t2 = Time() MsgBox "运行时间:" & Format(t2 - t1, "nn分ss秒") Application.ScreenUpdating = True End Sub 原为: Private Sub CommandButton11_Click() Dim a%, b%, c%, d%, e%, n% a = Range("a1").End(xlDown).Row - 1 b = Range("b1").End(xlDown).Row - 1 c = Range("c1").End(xlDown).Row - 1 d = Range("d1").End(xlDown).Row - 1 e = Range("e1").End(xlDown).Row - 1 n = a * b * c * d * e For k = 0 To n - 1 Sheets(2).Range("a" & k + 2) = Cells(Int(k / (b * c * d * e)) + 2, 1) Sheets(2).Range("b" & k + 2) = Cells(Int(k / (c * d * e) Mod b) + 2, 2) Sheets(2).Range("c" & k + 2) = Cells(Int(k / (d * e) Mod c) + 2, 3) Sheets(2).Range("d" & k + 2) = Cells((Int(k / e) Mod d) + 2, 4) Sheets(2).Range("e" & k + 2) = Cells((k Mod e) + 2, 5) Next End Sub
|