简体   繁体   English

Excel中的大+偏移功能

[英]Large + Offset Function in excel

I am trying to get top three large data from another sheet by using offset along with match but after running the below code, I am getting #VALUE error in the cell. 我试图通过使用offset和match从另一个工作表中获取前三个大数据,但是运行下面的代码后,我在单元格中遇到#VALUE错误。 I don't know why there is an error and how to resolve it. 我不知道为什么会有错误以及如何解决。

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

use different columns to write the results. 使用不同的列来写结果。

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