1
我已經添加了一個VBA代碼給我的Excel,它所做的是自動寫入其餘的號碼(例如:當我寫2
並點擊輸入它將它上面的數字,並填寫990112
[查看圖])Excel VBA代碼錯誤,當使用數量增量(CTRL拖動)
當每個號碼鍵入這工作得很好,但是當我使用自動增量(CTRL + Drag)
它拋出一個錯誤
這是我的VBA代碼
Private Sub Worksheet_Change(ByVal Target As Range)
Dim oldText As String, aboveText As String, newText As String
If Target.Column = 3 Then
oldText = Target.Text
aboveText = Target.Cells(0, 1).Text
If aboveText <> "DESIGN" Or Target.Text <> "" Then
If Len(aboveText) = 6 And Len(oldText) < 6 And Len(oldText) >= 1 Then
Application.EnableEvents = False
newText = Left(aboveText, 6 - Len(oldText)) + oldText
Target.Value = newText
Application.EnableEvents = True
End If
End If
End If
End Sub