簡體   English   中英

Excel中的大+偏移功能

[英]Large + Offset Function in excel

我試圖通過使用offset和match從另一個工作表中獲取前三個大數據,但是運行下面的代碼后,我在單元格中遇到#VALUE錯誤。 我不知道為什么會有錯誤以及如何解決。

Sub Dashboard()

Dim i As Integer, a As Integer, j As Integer, sh As Worksheet

Set sh = ThisWorkbook.Sheets("Dashboard")
a = sh.Range("B3", sh.Range("B3").End(xlDown)).Rows.Count

Sheets("Dashboard").Activate
For i = 3 To a
    For j = 1 To 3
        If i < (a + 1) Then
            ref = Sheets("RE_PE_Comdy_FX_IR").Range("A2")
            ro = Application.Match(Cells(i, 2), Sheets("RE_PE_Comdy_FX_IR").Range("A3:A15000"), 0)
            Sheets("Dashboard").Activate
            co = Application.Match(Cells(2, 4),Sheets("RE_PE_Comdy_FX_IR").Range("A1:P1"), 0) - 1
            hei = Application.Match(Cells(i, 2), Sheets("RE_PE_Comdy_FX_IR").Range("A3:A15000"), 0)
            wid = 1
            Cells(i, 4) = Application.Large("Offset(ref, ro, co, hei, wid)", j)
        End If
    Next j
Next i
End Sub

使用不同的列來寫結果。

For i = 3 To a
For j = 1 To 3
    If i < (a + 1) Then
        Set ref = Sheets("RE_PE_Comdy_FX_IR").Range("A2")
        ro = Application.Match(Cells(i, 2), Sheets("RE_PE_Comdy_FX_IR").Range("A3:A15000"), 0)
        Sheets("Dashboard").Activate
        co = Application.Match(Cells(2, 4),Sheets("RE_PE_Comdy_FX_IR").Range("A1:P1"), 0) - 1
        hei = Application.Match(Cells(i, 2), Sheets("RE_PE_Comdy_FX_IR").Range("A3:A15000"), 0)
        wid = 1
        'Write to different columns maybe??
        Cells(i, 4 + j - 1) = Application.Large(ref.Offset(ro, co).Resize(hei, wid), j)
    End If
Next j
Next i

暫無
暫無

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

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