Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 967|回复: 3

[已解决]单元格设置了密码保护工作簿之后会出现 VBA 代码运行错误

[复制链接]
发表于 2022-10-9 23:59 | 显示全部楼层 |阅读模式
1学分
本帖最后由 zames 于 2022-10-11 14:23 编辑

单元格设置了密码保护工作簿之后会出现 VBA 代码运行错误,帮忙看下 VBA 代码怎么修改下,谢谢!
最佳答案
2022-10-9 23:59
Private Sub CommandButton1_Click()
  ........
    ActiveSheet.Unprotect
    [A3].Resize(60000, 8).ClearContents
    [i3].Resize(60000, 1).ClearContents
    If num > 0 Then
        [A3].Resize(num, 8) = jrr
        [i3].Resize(num, 1) = krr
    End If
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic

    Dim x As Integer, mrr, h As Integer, Nrr(), z As Integer
    h = Cells(Rows.Count, "I").End(xlUp).Row
    If h = 1 Then Exit Sub
    mrr = Range("I3:I" & h)
    For x = 1 To UBound(mrr, 1)
        z = z + 1
        ReDim Preserve Nrr(1 To z)
        Nrr(z) = Range("BE25").Value & mrr(x, 1)
    Next x
    Range("I3").Resize(z) = Application.Transpose(Nrr)
    ActiveSheet.Protect
End Sub

模板.zip

442.06 KB, 下载次数: 4

最佳答案

查看完整内容

Private Sub CommandButton1_Click() ........ ActiveSheet.Unprotect [A3].Resize(60000, 8).ClearContents .Resize(60000, 1).ClearContents If num > 0 Then [A3].Resize(num, 8) = jrr .Resize(num, 1) = krr End If Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic Dim x As Integer, mrr, h As Integer, Nrr(), z As ...
发表于 2022-10-9 23:59 | 显示全部楼层    本楼为最佳答案   
Private Sub CommandButton1_Click()
  ........
    ActiveSheet.Unprotect
    [A3].Resize(60000, 8).ClearContents
    [i3].Resize(60000, 1).ClearContents
    If num > 0 Then
        [A3].Resize(num, 8) = jrr
        [i3].Resize(num, 1) = krr
    End If
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic

    Dim x As Integer, mrr, h As Integer, Nrr(), z As Integer
    h = Cells(Rows.Count, "I").End(xlUp).Row
    If h = 1 Then Exit Sub
    mrr = Range("I3:I" & h)
    For x = 1 To UBound(mrr, 1)
        z = z + 1
        ReDim Preserve Nrr(1 To z)
        Nrr(z) = Range("BE25").Value & mrr(x, 1)
    Next x
    Range("I3").Resize(z) = Application.Transpose(Nrr)
    ActiveSheet.Protect
End Sub
回复

使用道具 举报

 楼主| 发表于 2022-10-10 23:55 | 显示全部楼层
本帖最后由 zames 于 2022-10-11 14:24 编辑

有老师帮忙看看,谢谢!
回复

使用道具 举报

 楼主| 发表于 2022-10-12 12:54 | 显示全部楼层
zjdh 发表于 2022-10-9 23:59
Private Sub CommandButton1_Click()
  ........
    ActiveSheet.Unprotect

多谢帮忙!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-29 23:25 , Processed in 0.352024 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表