简体   繁体   English

Excel - 单元格在 VBA 宏运行后锁定

[英]Excel - Cells are locking after VBA macro runs

I have a macro that's using a loop to take data from one sheet and copy it to another, putting them in an order determined by an array.我有一个宏,它使用循环从一张纸中获取数据并将其复制到另一张纸上,将它们按照由数组确定的顺序排列。 Relevant code:相关代码:

For counter = 1 To 358 Step 1
    Sheets("data").Cells(inputrow, counter + 1) = Sheets("Sheet1").Cells(rowarray(counter), colarray(counter))
    Sheets("sheet1").Cells(rowarray(counter), colarray(counter)).Clear
Next counter

The input sheet is protected, with the cells that you put data unlocked, but every time I run the macro those cells get locked again.输入表受到保护,您放置数据的单元格已解锁,但每次我运行宏时,这些单元格都会再次被锁定。 I have no idea what's causing this and it's driving me nuts.我不知道是什么原因造成的,这让我抓狂。 Please help!请帮忙!

.Clear was stripping the unlocked formatting. .Clear正在剥离解锁的格式。 Use .ClearContents instead. 请改用.ClearContents

I was facing the same problem when I ran a macro the unlocked cells would automatically get locked and stopped macro functioning.当我运行宏时,我遇到了同样的问题,解锁的单元格会自动被锁定并停止宏功能。 After changing it to.ClearContents it worked and now the part of the sheet that I want protected is now password protected.将其更改为 .ClearContents 后,它起作用了,现在我想要保护的工作表部分现在受密码保护。 Thanks谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM