Excel VBA代码错误,使用数字递增(CTRL拖动)

我已经添加了一个VBA代码到我的Excel中,它所做的是自动写入其余的数字(例如:当我写2并input它将采取上面的数字,并填写到990112 [见img])

当每个数字键入时,这工作正常,但是当我使用自动增量(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 

Excel文件

更改

 If Target.Column = 3 Then 

 If Target.Column = 3 And Target.Cells.Count = 1 Then 

您正在尝试获取多单元格区域的Text属性(在此情况下为“目标”为C6:C7)。 新的线路将确保您只更改一个单元格。