具有数组和调整大小的多像元值输入

问题描述

我目前在代码中使用此结构:

With Worksheets("Vendredi jour")
.Unprotect
.Cells(15,43).Resize(1,6).Value = Array(B,C,D,E,F,G) ' Mets les minutes dans le tableau de compilations
.Protect
End With

由于它是作为上帝的礼物送给我的,所以我不明白它是如何工作的,这是有问题的,因为我想将其应用于此:

  With Worksheets("Vendredi jour")
    .Unprotect
    
    .Cells(9,41).Value = MyArray(0,0) ' (x,0) = Employé
    .Cells(10,41).Value = MyArray(1,0)
    .Cells(11,41).Value = MyArray(2,0)
    .Cells(12,41).Value = MyArray(3,0)
    .Cells(13,41).Value = MyArray(4,0)

    .Cells(9,44).Value = MyArray(0,1) ' (x,1) = Passes
    .Cells(10,44).Value = MyArray(1,1)
    .Cells(11,44).Value = MyArray(2,1)
    .Cells(12,44).Value = MyArray(3,1)
    .Cells(13,44).Value = MyArray(4,1)

    .Cells(9,46).Value = MyArray(0,2) ' (x,2) = Pertes
    .Cells(10,46).Value = MyArray(1,2)
    .Cells(11,46).Value = MyArray(2,2)
    .Cells(12,46).Value = MyArray(3,2)
    .Cells(13,46).Value = MyArray(4,2)
    
    .Protect
    End With

是否有任何说明文档?

解决方法

With Worksheets("Vendredi jour")
    .Unprotect
    .Cells(15,43).Resize(1,6).Value = Array(B,C,D,E,F,G) 
    .Protect
End With

在功能上与

相同
Worksheets("Vendredi jour").Unprotect
Worksheets("Vendredi jour").Cells(15,G) 
Worksheets("Vendredi jour").Protect

使用With的版本更易于阅读,并且具有一些轻微性能优势。

如果需要更多详细信息,请参见VBA - What is the purpose of the `With` statement

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...