长数组公式将分成较小的部分(VBA)

时间:2019-10-04 19:31:59

标签: excel vba

我有一个长数组公式,我试图将其分解成较小的部分以便通过VBA应用,这是工作公式(在Excel中):

private fun setUpTimeLapseMediaRecorder(): MediaRecorder {
    val resolver = context.contentResolver
    val contentValues = ContentValues()
    val videoName = "time_lapse_video_" + System.currentTimeMillis() + ".mp4"
    val directoryName = "${Environment.DIRECTORY_DCIM}"
    val filePath = "${directoryName}Videos${File.separator}$videoName"

    contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, filePath)
    val uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, contentValues)

    val timeLapseMediaRecorder = MediaRecorder()
    timeLapseMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE)
    timeLapseMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_720P))
    timeLapseMediaRecorder.setOutputFile(/* How i can get file path from media store?*/)
    timeLapseMediaRecorder.setVideoFrameRate(60)
    timeLapseMediaRecorder.setCaptureRate(1.8)

    timeLapseMediaRecorder.prepare()

    return timeLapseMediaRecorder
}

这是VBA中的代码:

=IF(C7="MOR",IFERROR(IFERROR(INDEX($K$7:$K$43,MATCH(1,(E7=$I$7:$I$43)*("MOR"=$C$7:$C$43),0)),INDEX($K$7:$K$43,MATCH(1,(E7=$I$7:$I$43)*("AFT"=$C$7:$C$43),0))),INDEX($K$7:$K$43,MATCH(1,(E7=$I$7:$I$43)*("EVE"=$C$7:$C$43),0))),IF(C7="AFT",IFERROR(IFERROR(INDEX($K$7:$K$43,MATCH(1,(E7=$I$7:$I$43)*("AFT"=$C$7:$C$43),0)),INDEX($K$7:$K$43,MATCH(1,(E7=$I$7:$I$43)*("EVE"=$C$7:$C$43),0))),INDEX($K$7:$K$43,MATCH(1,(E7=$I$7:$I$43)*("MOR"=$C$7:$C$43),0))),IFERROR(IFERROR(INDEX($K$7:$K$43,MATCH(1,(E7=$I$7:$I$43)*("EVE"=$C$7:$C$43),0)),INDEX($K$7:$K$43,MATCH(1,(E7=$I$7:$I$43)*("AFT"=$C$7:$C$43),0))),INDEX($K$7:$K$43,MATCH(1,(E7=$I$7:$I$43)*("MOR"=$C$7:$C$43),0)))))

我遇到错误

  

运行时错误'1004':无法设置Range类的FormulaArray属性

此处:

Dim part1, part2, part3 As String
Dim part1, part2, part3 As String

part1 = "=IF(C7=""MOR"",IFERROR(IFERROR(INDEX($K$7:$K$43,MATCH(1,(E7=$I$7:$I$43)*(""MOR""=$C$7:$C$43),0)),INDEX($K$7:$K$43,MATCH(1,(E7=$I$7:$I$43)*(""AFT""=$C$7:$C$43),0))),INDEX($K$7:$K$43,MATCH(1,(E7=$I$7:$I$43)*(""EVE""=$C$7:$C$43),0))) ,(""XXX2""))  "
part2 = ",IF(C7=""AFT"",IFERROR(IFERROR(INDEX($K$7:$K$43,MATCH(1,(E7=$I$7:$I$43)*(""AFT""=$C$7:$C$43),0)),INDEX($K$7:$K$43,MATCH(1,(E7=$I$7:$I$43)*(""EVE""=$C$7:$C$43),0))),INDEX($K$7:$K$43,MATCH(1,(E7=$I$7:$I$43)*(""MOR""=$C$7:$C$43),0))) ,(""XXX3"")  "
part3 = ",IFERROR(IFERROR(INDEX($K$7:$K$43,MATCH(1,(E7=$I$7:$I$43)*(""EVE""=$C$7:$C$43),0)),INDEX($K$7:$K$43,MATCH(1,(E7=$I$7:$I$43)*(""AFT""=$C$7:$C$43),0))),INDEX($K$7:$K$43,MATCH(1,(E7=$I$7:$I$43)*(""MOR""=$C$7:$C$43),0))))) "


With ActiveSheet.Range("W7")
.FormulaArray = part1
.Replace "XXX2", part2
.Replace "XXX3", part3
End With 

我不明白的是,如果我从Excel的直接窗口复制粘贴VBA代码,该公式不会给我任何错误。

我也算过字符,空格有246个。

所以我想知道,除了如何解决这个问题之外,我在做什么错了?

0 个答案:

没有答案