Da waren sie wieder – meine drei Probleme: Vergesslichkeit, Dings und das Andere.

Lieber René,

ich hoffe, es geht dir gut. Darf ich dir eine kurze Frage VBA stellen? Folgende Situation:

Ich habe eine geodätische Kuppel gebaut und möchte ein Gleichungssystem mit 3 Gleichungen und 3 Unbekannten zu lösen:

Function GleichungsSystemMatrix3x3und1x3Parameter(Matrix1 As Range, Matrix2 As Range) As Variant
GleichungsSystemMatrix3x3und1x3Parameter = Application.WorksheetFunction.MMult(Application.WorksheetFunction.MInverse(Matrix1), Matrix2)
End Function

Und jetzt kommts: Da kommen also 3 Parameter r, t und w raus (so will ich sie später nennen) und die hätte ich gerne in Variablen geschrieben und eben nicht gleich in die Excelzellen, wie das der obige Code halt macht.

Hättest du eine Idee und Lust zu helfen?

LG, Axel

moin Axel,

du musst die Arrays richtig zusammenbauen, dann klappt es. Das Überwachungsfenster hat mir geholfen.

Sub LösungBerechnen()
Dim Matrix(2, 2) As Double
Dim Lö1(2, 2) As Double
Dim R1 As Double
Dim R2 As Double
Dim R3 As Double
Dim T1 As Double
Dim T2 As Double
Dim T3 As Double
Dim W1 As Double
Dim W2 As Double
Dim W3 As Double
Dim L1 As Double
Dim L2 As Double
Dim L3 As Double

R1 = 5
R2 = 3
R3 = 2
T1 = -1
T2 = 2
T3 = 2
W1 = 7
W2 = 5
W3 = 8

L1 = 3
L2 = 4
L3 = 1

Matrix(0, 0) = R1: Matrix(1, 0) = R2: Matrix(2, 0) = R3
Matrix(0, 1) = T1: Matrix(1, 1) = T2: Matrix(2, 1) = T3
Matrix(0, 2) = W1: Matrix(1, 2) = W2: Matrix(2, 2) = W3

Lö1(0, 0) = L1: Lö1(1, 0) = L2: Lö1(2, 0) = L3

MsgBox GleichungsSystemMatrix3x3und1x3Parameter_L1(Matrix, Lö1)
MsgBox GleichungsSystemMatrix3x3und1x3Parameter_L2(Matrix, Lö1)
MsgBox GleichungsSystemMatrix3x3und1x3Parameter_L3(Matrix, Lö1)

End Sub

Function GleichungsSystemMatrix3x3und1x3Parameter_L1(Matrix1 As Variant, Matrix2 As Variant) As Double
Dim Lösung As Variant
Lösung = Application.WorksheetFunction.mmult(Application.WorksheetFunction.MInverse(Matrix1), Matrix2)
GleichungsSystemMatrix3x3und1x3Parameter_L1 = Lösung(1, 1)
End Function

Function GleichungsSystemMatrix3x3und1x3Parameter_L2(Matrix1 As Variant, Matrix2 As Variant) As Double
Dim Lösung As Variant
Lösung = Application.WorksheetFunction.mmult(Application.WorksheetFunction.MInverse(Matrix1), Matrix2)
GleichungsSystemMatrix3x3und1x3Parameter_L2 = Lösung(2, 1)
End Function

Function GleichungsSystemMatrix3x3und1x3Parameter_L3(Matrix1 As Variant, Matrix2 As Variant) As Double
Dim Lösung As Variant
Lösung = Application.WorksheetFunction.mmult(Application.WorksheetFunction.MInverse(Matrix1), Matrix2)
GleichungsSystemMatrix3x3und1x3Parameter_L3 = Lösung(3, 1)
End Function

Liebe Grüße :: Rene

Ich beurteile Menschen nicht nach Aussehen, Hautfarbe oder Religion. Sondern wie sie sich benehmen, wenn eine zweite Kasse geöffnet wird.

Das ist bösartig! In einem Exceldokument sollen Werte von Eigenschaftsfeldern, die von SAP kommen, in die Kopfzeile geschrieben werden. Also von:

Nach:

Der Befehl für diese Felder ist schnell gefunden:

ContentTypeProperties(„Target group“)

Das Makro:

Dim strTitle As String
Dim strLocation As String
Dim strTarget As String
Dim strType As String

strTitle = ThisWorkbook.BuiltinDocumentProperties("Title").Value
strLocation = ThisWorkbook.ContentTypeProperties("Location").Value
strTarget = ThisWorkbook.ContentTypeProperties("Target group").Value
strType = ThisWorkbook.ContentTypeProperties("Document type").Value

If strTitle <> "" Then strTitle = " " & strTitle
If strLocation <> "" Then strLocation = " " & strLocation
If strTarget <> "" Then strTarget = " " & strTarget
If strType <> "" Then strType = " " & strType

With ActiveSheet.PageSetup
    .LeftHeader = Replace(.LeftHeader, "Title", "Title" & strTitle)
    .LeftHeader = Replace(.LeftHeader, "Location", "Location" & strLocation)
    .LeftHeader = Replace(.LeftHeader, "Target group", "Target group" & strTarget)
    .LeftHeader = Replace(.LeftHeader, "Document type", "Document type" & strType)
End With

Ein Durchlauf mit leeren Feldern – klappt! Ein Durchlauf mit Daten bringt die Fehlermeldung 13: Typen unverträglich. Ich stutze. Ich untersuche die Inhalte. tatsächlich: die Daten, die aus Sharepoint kommen, sind keine Texte, sondern Datenfelder. Bestehend aus zwei Werten: Inhalt und ID. Sieht man aber nicht:

Nun das kann man abprüfen:

Dim strTitle As String
Dim strLocation As String
Dim strTarget As String
Dim strType As String

If TypeName(ThisWorkbook.BuiltinDocumentProperties("Title").Value) = "String()" Then
    If UBound(ThisWorkbook.BuiltinDocumentProperties("Title").Value) >= 0 Then
        strTitle = ThisWorkbook.BuiltinDocumentProperties("Title").Value(0)
    End If
ElseIf TypeName(ThisWorkbook.BuiltinDocumentProperties("Title").Value) = "String" Then
    strTitle = ThisWorkbook.BuiltinDocumentProperties("Title").Value
End If

If TypeName(ThisWorkbook.ContentTypeProperties("Location").Value) = "String()" Then
    If UBound(ThisWorkbook.ContentTypeProperties("Location").Value) >= 0 Then
        strLocation = ThisWorkbook.ContentTypeProperties("Location").Value(0)
    End If
ElseIf TypeName(ThisWorkbook.ContentTypeProperties("Location").Value) = "String" Then
    strLocation = ThisWorkbook.ContentTypeProperties("Location").Value
End If

If TypeName(ThisWorkbook.ContentTypeProperties("Target group").Value) = "String()" Then
    If UBound(ThisWorkbook.ContentTypeProperties("Target group").Value) >= 0 Then
        strTarget = ThisWorkbook.ContentTypeProperties("Target group").Value(0)
    End If
ElseIf TypeName(ThisWorkbook.ContentTypeProperties("Target group").Value) = "String" Then
    strTarget = ThisWorkbook.ContentTypeProperties("Target group").Value
End If

If TypeName(ThisWorkbook.ContentTypeProperties("Document type").Value) = "String()" Then
    If UBound(ThisWorkbook.ContentTypeProperties("Document type").Value) >= 0 Then
        strType = ThisWorkbook.ContentTypeProperties("Document type").Value(0)
    End If
ElseIf TypeName(ThisWorkbook.ContentTypeProperties("Document type").Value) = "String" Then
    strType = ThisWorkbook.ContentTypeProperties("Document type").Value
End If

If strTitle <> "" Then strTitle = " " & strTitle
If strLocation <> "" Then strLocation = " " & strLocation
If strTarget <> "" Then strTarget = " " & strTarget
If strType <> "" Then strType = " " & strType

With ActiveSheet.PageSetup
' -- schreibe nur rein, falls der Text noch nicht drinsteht.
    If InStr(1, .LeftHeader, "Title" & strTitle) = 0 Then
        .LeftHeader = Replace(.LeftHeader, "Title", "Title" & strTitle)
    End If
    If InStr(1, .LeftHeader, "Location" & strLocation) = 0 Then
        .LeftHeader = Replace(.LeftHeader, "Location", "Location" & strLocation)
    End If
    If InStr(1, .LeftHeader, "Target group" & strTarget) = 0 Then
        .LeftHeader = Replace(.LeftHeader, "Target group", "Target group" & strTarget)
    End If
    If InStr(1, .LeftHeader, "Document type" & strType) = 0 Then
        .LeftHeader = Replace(.LeftHeader, "Document type", "Document type" & strType)
    End If
End With

Und dann klappt es auch: