简体   繁体   中英

VBA right way of clearing/resetting an excel document?

So, I found a bit of code on a website a few weeks ago that worked perfectly for what I need but I am just wondering what exactly the following bit of code does because to me it makes more sense to clear the document using MainSheet1.Cells.Clear and then just do a series of Range("Z1").Value = "Group" for example

Why has this person chose to make an array and fill it in that way...?

Sub CLEAR_DOCUMENT()

    '
    Dim headers(1 To 4, 1 To 15) As Variant

    MainSheet1.Cells.Clear

    headers(4, 1) = "Group"
    headers(4, 2) = "Look"
    headers(4, 3) = "Time"
    headers(4, 4) = "Tie"
    headers(4, 5) = "Type"
    headers(4, 6) = "Name"
    headers(4, 7) = "Num"
    headers(1, 8) = "School 2"
    headers(1, 9) = "Group 2"
    headers(2, 8) = "*"
    headers(2, 9) = ">0"
    headers(1, 11) = "Time"
    headers(1, 12) = "Language"
    headers(1, 13) = "School 1"
    headers(1, 14) = "Age"
    headers(1, 15) = "Eng"

    MainSheet1.Range("Z1:AN4").Value = headers

    Application.EnableEvents = True

End Sub

您发布的代码比一次填充一个单元格要快得多。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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