簡體   English   中英

如何使用具有一系列值的自動填充/填充

[英]How to use Autofill/Filldown with a range of values

我一直試圖讓 Excel 將公式應用於一組列,然后將模式擴展到整個行集。 這導致了以下代碼:

For i = 0 To avgsheetNames.Count - 1
If Contains(CStr(avgsheetNames(i)), "Scores") = True Then
    With mainWorkBook.Worksheets(avgsheetNames(i))
        strFormulas(1) = "=SUM(Aggregated_Internal_Scores!I2:I7)/6"
        strFormulas(2) = "=SUM(Aggregated_Internal_Scores!J2:J7)/6"
        strFormulas(3) = "=SUM(Aggregated_Internal_Scores!K2:K7)/6"
        strFormulas(4) = "=SUM(Aggregated_Internal_Scores!L2:L7)/6"
        strFormulas(5) = "=SUM(Aggregated_Internal_Scores!M2:M7)/6"
        strFormulas(6) = "=SUM(Aggregated_Internal_Scores!N2:N7)/6"
        
        strFormulas2(1) = "=SUM(Aggregated_Internal_Scores!I8:I13)/6"
        strFormulas2(2) = "=SUM(Aggregated_Internal_Scores!J8:J13)/6"
        strFormulas2(3) = "=SUM(Aggregated_Internal_Scores!K8:K13)/6"
        strFormulas2(4) = "=SUM(Aggregated_Internal_Scores!L8:L13)/6"
        strFormulas2(5) = "=SUM(Aggregated_Internal_Scores!M8:M13)/6"
        strFormulas2(6) = "=SUM(Aggregated_Internal_Scores!N8:N13)/6"

        mainWorkBook.Worksheets(avgsheetNames(i)).Range("C2:H2").Formula = strFormulas
        mainWorkBook.Worksheets(avgsheetNames(i)).Range("C3:H3").Formula = strFormulas2
        mainWorkBook.Worksheets(avgsheetNames(i)).Range("C2:H3").AutoFill Destination:=mainWorkBook.Worksheets(avgsheetNames(i)).Range("C2:H32")
        
    End With
End If

正如你所看到的,我試圖提供我想要的模式,從“Aggregated_Internal_Scores”表中提取的值應該遵循模式I2:I7 > I8:I13 > I14:I19等等。

但是,執行宏后,我得到的是I2:I7 > I8:I13 > I4:I9 > I10:I15嗎?

似乎 Excel 將塊 C2:H3 作為模式,並且在每個塊的開頭僅增加 2。

誰能解釋我哪里出錯了,以及我如何指定我希望提取工作表值遵循某種模式?

先感謝您!

利用:

mainWorkBook.Worksheets(avgsheetNames(i)).Range("C2:H32").Formula = "=SUM(INDEX(Aggregated_Internal_Scores!I:I,(ROW($ZZ1)-1)*6+2):INDEX(Aggregated_Internal_Scores!I:I,(ROW($ZZ1)-1)*6+7))/6"

用它替換If中的所有內容。


如果有 Office 365 和動態數組公式,則使用:

mainWorkBook.Worksheets(avgsheetNames(i)).Range("C2:H32").Formula2 = "=SUM(INDEX(Aggregated_Internal_Scores!I:I,SEQUENCE(6,,(ROW($ZZ1)-1)*6+2))/6"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM