0

## Excel-資料輸入至其他工作表(速度問題)

``````Sub 存到資料庫()
'Application.ScreenUpdating = False
'Application.EnableEvents = False
'Application.Interactive = False

'1.判斷儲存在資料庫的哪一列
If Sheets("訂單資料庫").Range("A2") = "" Then
r = 2
Else
r = Sheets("訂單資料庫").Range("A2").End(xlDown).Row + 1
End If

'訂單輸入介面Item欄位到第幾列
r2 = Sheets("訂單輸入介面").Range("B4").End(xlDown).Row

For i = 5 To r2
'Item
Sheets("訂單資料庫").Cells(r + i - 5, 2) = Sheets("訂單輸入介面").Cells(i, 2)
'客戶、下單日期、交期等其他欄位依序輸入

Next i

Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Interactive = True

End Sub
``````

### 1 個回答

2
paicheng0111
iT邦高手 1 級 ‧ 2019-12-09 11:59:21

try this

``````Sub 存到資料庫()
Dim r2 As Range

Application.ScreenUpdating = False

With Sheets("訂單輸入介面")
Set r2 = .Range(.Range("B5"), .Range("B4").End(xlDown))
End With

With Sheets("訂單資料庫").Range("A2")
If .Value = "" Then
.resize(r2.rows.count, 1).value = r2.value
Else
.End(xlDown).Offset(1).resize(r2.rows.count, 1).value = r2.value
End If
End With
Application.ScreenUpdating = True
End Sub
``````