当处理空值时,我正处理着名INDEX()
返回0的问题。
我使用Variant
变量放置值,然后将其与“”进行比较,如果等于“”则替换为“”(Excel逻辑...)。问题是它是一个循环并且每次都不起作用时重复使用相同的Variant变量(在它开始给出零的第一行之后它应该给出空白,最后它返回类型不匹配错误)。
我最终使用了一系列变体,因此每个循环步骤的变量都是新的。它有效,但我认为它无效,我该如何改进它(重用变量CurrCellValue
?)?
Dim CurrCellValue() As Variant
ReDim CurrCellValue(2 To LowerLastHistoryLine, 4 To 55) As Variant
For CurrLine = 2 To LowerLastHistoryLine
For CurrCol = 4 To 55
On Error Resume Next
CurrCellValue(CurrLine, CurrCol) = _
WorksheetFunction.Index(Sheets("История_прогноз").Range("A1:" & Sheets("История_прогноз").Cells(LastDataLine, LastHistCol).Address(False, False)), _
WorksheetFunction.Match(Sheets("Seas_Lower").Cells(CurrLine, 3).Value, Sheets("История_прогноз").Range("A:A"), 0), _
WorksheetFunction.Match(Sheets("Seas_Lower").Cells(1, CurrCol).Value & "." & Sheets("Seas_Lower").Cells(CurrLine, 2).Value, _
Sheets("История_прогноз").Range("1:1"), 0))
On Error GoTo 0
If CurrCellValue(CurrLine, CurrCol) = "" Then 'type mismatch here
Sheets("Seas_Lower").Cells(CurrLine, CurrCol).Value = ""
Else
Sheets("Seas_Lower").Cells(CurrLine, CurrCol).Value = WorksheetFunction.IfError(CurrCellValue(CurrLine, CurrCol), "")
End If
Next CurrCol
Next CurrLine