# Excelマクロの配列計算が♯VALUE!となる

• すぐに回答を！
• 質問No.9586827
• 閲覧数44
• ありがとう数1
• 気になる数0
• 回答数1

お礼率 90% (9/10)

Excelマクロの複素数を扱う配列計算がエラーとなります．
下記HPからマクロを標準モジュールに取り込み，以前のＱＡで助けて頂き

しかし，このマクロで定義した「 IMINVERS 」関数を実行すると，大きい

http://www.geocities.jp/tomtomf/denki/AC2/ac2.htm
http://www.geocities.jp/tomtomf/denki/AC1/ac1.htm

〔問題の現象〕
整数の行列（６×６）以上の配列計算は「#VALUE!」となる．
複素数の行列（５×５）以上の配列計算は「#VALUE!」となってしまう．

どこに問題があるのでしょうか．

-----------------------------------------------------------

Public Function IMABSa(a As Variant) As Variant

IMABSa = Application.WorksheetFunction.ImAbs(a)

End Function

Public Function IMDIVa(a As Variant, b As Variant) As Variant

IMDIVa = Application.WorksheetFunction.ImDiv(a, b)

End Function

Public Function IMPRODUCTa(ParamArray a()) As Variant

IMPRODUCTa = Application.WorksheetFunction.ImProduct(a)

End Function

Public Function IMPRODUCTb(a As Variant, b As Variant) As Variant

IMPRODUCTb = Application.WorksheetFunction.ImProduct(a, b)

End Function

Public Function IMSUBa(a As Variant, b As Variant) As Variant

IMSUBa = Application.WorksheetFunction.ImSub(a, b)

End Function

Public Function IMSUMa(ParamArray a()) As Variant

IMSUMa = Application.WorksheetFunction.ImSum(a)

End Function

Public Function IMSUMb(a As Variant) As Variant

IMSUMb = Application.WorksheetFunction.ImSum(a)

End Function

-----------------------------------------------------
Public Function IMINVERS(a As Range) As Variant

Dim n As Integer, n1 As Integer, n2 As Integer
Dim r1 As Integer, r2 As Integer, c As Integer
Dim max As Variant
Dim i As Integer
Dim m() As Variant
Dim inm() As Variant
Dim rr As Integer, cc As Integer
Dim no As Integer, ex As Variant

n1 = a.Rows.Count
n2 = a.Columns.Count
n = n1

ReDim inm(1 To n1, 1 To n2)

For rr = 1 To n1
For cc = 1 To n2
If rr <> cc Then
inm(rr, cc) = 0
Else
inm(rr, cc) = 1
End If

Next
Next

ReDim m(1 To n1, 1 To n2)
m = a

If n1 <> n2 Then
IMINVERS = False
Exit Function
End If

For r1 = 1 To n
max = m(r1, r1)
no = r1

If r1 < n Then

For i = r1 + 1 To n

If IMABSa(m(i, r1)) > IMABSa(max) Then
max = m(i, r1)
no = i
End If

Next

If (r1 <> no) Then
For i = 1 To n
ex = m(r1, i)
m(r1, i) = m(no, i)
m(no, i) = ex
Debug.Print m(r1, i), m(no, i)
ex = inm(r1, i)
inm(r1, i) = inm(no, i)
inm(no, i) = ex
Next
End If
End If

max = m(r1, r1)

For i = 1 To n
m(r1, i) = IMDIVa(m(r1, i), max)
inm(r1, i) = IMDIVa(inm(r1, i), max)
Next

For r2 = 1 To n
If r1 <> r2 Then
max = m(r2, r1)

For i = 1 To n
m(r2, i) = IMSUBa(m(r2, i), IMPRODUCTa(m(r1, i), max))
inm(r2, i) = IMSUBa(inm(r2, i), IMPRODUCTa(inm(r1, i), max))
Next
End If
Next
Next

IMINVERS = inm

End Function
------------------------------------------------

### 回答 （全1件）

• 回答No.1

ベストアンサー率 44% (4138/9344)

マクロの計算では
inm(r1, i) = IMDIVa(inm(r1, i), max)
で0で割ることになってしまいます。
AIエージェント「あい」

こんにちは。AIエージェントの「あい」です。
あなたの悩みに、OKWAVE 3,500万件のQ&Aを分析して最適な回答をご提案します。

その他の関連するQ&A、テーマをキーワードで探す

キーワードでQ&A、テーマを検索する
• ICON_arr
• ICON_arr
• ICON_arr
• ICON_arr

OKWAVE若者応援スペシャル企画

AIがおススメ！知っておきたいQ&A

リアルタイムランキング毎分更新

ピックアップ

カテゴリ