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