【发布时间】:2016-12-21 05:53:41
【问题描述】:
这是我创建的用户表单。然后,它被用作输入平台。有一些不同的表,例如 2016 年,2017 年......该保存按钮的逻辑是搜索用户输入的年份(日期)并定位正确的工作表。然后,它将找到该工作表的最后一行。
例如,最后一行是第1000行。用户表单的第一行将保存在第1001行。用户表单的第二行将保存在第1002行......
问题
但是,当我在真正的 excel 文件中测试时,保存速度太慢了。由于真正的 excel 文件很大(每个工作表中大约 1XXXX 行)。它使用 8 秒保存一行用于用户窗体,13 秒到保存两行。
显然,保存速度是不可接受的。有什么方法可以改善吗?
If ComboBox3.Value = "2016" Then
Worksheets("2016").Activate
j = WorksheetFunction.CountA(Worksheets("2016").Range("A:A")) + 1
End If
If ComboBox3.Value = "2017" Then
Worksheets("2017").Activate
j = WorksheetFunction.CountA(Worksheets("2017").Range("A:A")) + 1
End If
'1st
If ComboBox4.Value = "" Then
Else
Cells(j, 1) = ComboBox434.Value
Cells(j, 5) = ComboBox1.Value
Cells(j, 4) = ComboBox2.Value
Cells(j, 3) = ComboBox3.Value
If ComboBox4.ListIndex <> -1 Then
Cells(j, 6) = TimeValue(ComboBox4.Value & ":" & ComboBox5.Value)
Cells(j, 24) = ComboBox4.Value
Cells(j, 25) = ComboBox5.Value
Else
Cells(j, 6) = ""
End If
Cells(j, 7) = ComboBox6.Value
Cells(j, 8) = ComboBox7.Value
Cells(j, 9) = ComboBox8.Value
Cells(j, 10) = TextBox2.Value
Cells(j, 11) = TextBox3.Value
Cells(j, 12) = TextBox4.Value
Cells(j, 13) = TextBox5.Value
Cells(j, 14) = TextBox42.Value
Cells(j, 15) = TextBox43.Value
Cells(j, 16) = TextBox44.Value
Cells(j, 17) = TextBox666.Value
'If ComboBox4.Value = "" Then
End If
'2nd
j = j + 1
If ComboBox9.Value = "" Then
Else
Cells(j, 1) = ComboBox434.Value
Cells(j, 5) = ComboBox1.Value
Cells(j, 4) = ComboBox2.Value
Cells(j, 3) = ComboBox3.Value
If ComboBox9.ListIndex <> -1 Then
Cells(j, 6) = TimeValue(ComboBox9.Value & ":" & ComboBox10.Value)
Cells(j, 24) = ComboBox9.Value
Cells(j, 25) = ComboBox10.Value
Else
Cells(j, 6) = ""
End If
Cells(j, 7) = ComboBox11.Value
Cells(j, 8) = ComboBox12.Value
Cells(j, 9) = ComboBox13.Value
Cells(j, 10) = TextBox6.Value
Cells(j, 11) = TextBox7.Value
Cells(j, 12) = TextBox8.Value
Cells(j, 13) = TextBox9.Value
Cells(j, 14) = TextBox45.Value
Cells(j, 15) = TextBox46.Value
Cells(j, 16) = TextBox47.Value
Cells(j, 17) = TextBox617.Value
【问题讨论】:
-
除了更改为数据库之外,您对此无能为力。您可以通过将用户窗体控件保存到数组中,然后一次将数组写入单元格范围来节省一些时间。但我认为真正的障碍是用户表单读取和工作表写入。
-
或使用
ComboBox.LinkedCell属性
标签: vba performance excel processing-efficiency