excel - excel中的大+偏移功能
问题描述
我试图通过使用偏移量和匹配从另一张表中获取前三个大数据,但是在运行以下代码后,我在单元格中收到 #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
推荐阅读
- python - 检查某物是否是主要蟒蛇?
- ios - 在 swift 我在视图控制器之间传递 2 个字符串,我怎样才能将它们分开以在不同的功能中使用它们?
- python - 如何检测 X 射线图像中暗区域内的小圆圈?
- python - 函数中的 Kwargs
- python - 如何制作一个 Python 代码来确定从特定来源到达目的地的分钟数(基于字典值)?
- arrays - 在 SwiftUI 预览中初始化对象
- python - 将 Excel (*.xls) 文件组合成单个 (*.xlsx) 文件的经过测试的方法
- azure - 显示事件 41 增加的关键系统日志内核电源系统已重新启动,但未先彻底关闭
- javascript - 即使我只发送了一次响应(标头),我怎么知道是什么导致了这个错误 Error [ERR_HTTP_HEADERS_SENT]?
- python - 我的 Django 测试因 csrf_token 值而失败?