首页 > 解决方案 > 是否可以禁用 Excel 单元格中的“自动增量”功能?

问题描述

我的问题与 Excel 功能有关,它逐渐增加单元格的值,例如:

--------
   1
-------- <-- if I insert a row here
   1
--------

然后Excel“自动添加”到下面单元格中的值......就像这样

--------
   1
-------- 
   1       <-- new row inserted
--------
   2       <-- original value increased from 1 to 2
--------

是否可以关闭此功能?最好通过 VBA,因为我正在使用表单按钮和宏插入行。

谢谢。

编辑1:我尝试将单元格格式化为文本无济于事。

编辑 2:我如何插入新行

Dim row As Long
Dim varResponse As Variant
Application.ScreenUpdating = False

'Message box confirming user is doing the right thing
varResponse = MsgBox("Add another row? 'Yes' or 'No'", vbYesNo, "Add Row")
If varResponse <> vbYes Then Exit Sub

'Carry on with adding a row.....

'Unprotect sheet
ActiveSheet.Unprotect Password:="****"

'Insert new row on button row
row = ActiveSheet.Buttons(Application.Caller).TopLeftCell.row
Rows(row + 1).Insert

'AutoFill from 1 row above new row, for 1 row down
Rows(row).AutoFill Destination:=Rows(row + 1 & ":" & row), Type:=xlFillDefault

'Clear cells D-J on new row
Range("D" & row & ":J" & row).ClearContents

'Protect sheet again
ActiveSheet.Protect Password:="***"

标签: excelvba

解决方案


将 xlFillDefault 替换为 xlFillCopy 也可以执行您想要的操作,具体取决于您实际想要执行的操作。– GSerg


推荐阅读