PDA

View Full Version : Userform Help



ed1922
10-10-2016, 12:59 PM
Hi, I have a code that selects the current region from cell A1 and inverts the matrix entered in that region. I want the user to enter the matrix in a userform and not in Excel's cells. What can I do to accomplish this?

Paul_Hossler
10-10-2016, 03:05 PM
Here's a simple demo of using a userform to capture data and use it

ed1922
10-10-2016, 03:43 PM
Thanks, I want to create a similar userform but the matrix size may vary. This is the code and I want the variable "a" (matrix) to be in a textbox or anything similar where the user enters the values , is that possible? Like if what happened in the Current region just happened in the userform.


Dim a As Variant, c#(), x#, y#
Dim m&, u#, i&, j&, rv&()
Dim q&, w&
Set a = Cells(1).CurrentRegion
m = a.Rows.Count 'UBound(a, 1)
ReDim c(1 To m, 1 To m), rv(1 To m, 1 To 2)
For i = 1 To m: c(i, i) = 1: Next i
For q = 1 To m
u = 10 ^ 15
For i = 1 To m
If rv(i, 1) = 0 Then
If a(i, q) <> 0 Then
If (Log(a(i, q) ^ 2)) ^ 2 < u Then
u = (Log(a(i, q) ^ 2)) ^ 2
w = i
End If
End If
End If
Next i
rv(w, 1) = w: rv(q, 2) = w: x = a(w, q
For j = 1 To m
a(w, j) = a(w, j) / x
c(w, j) = c(w, j) / x
Next j
For i = 1 To m
If rv(i, 1) = 0 Then
y = a(i, q)
For j = 1 To m
a(i, j) = a(i, j) - y * a(w, j)
c(i, j) = c(i, j) - y * c(w, j)
Next j
End If
Next i
Next q 'BACK SOLUTION
For q = m To 2 Step -1
For w = q - 1 To 1 Step -1
x = a(rv(w, 2), q)
a(rv(w, 2), q) = a(rv(w, 2), q) - x * a(rv(q, 2), q)
For j = 1 To m
c(rv(w, 2), j) = c(rv(w, 2), j) - x * c(rv(q, 2), j)
Next j
Next w
Next q
For q = 1 To m
For j = 1 To m
a(q, j) = c(rv(q, 2), j)
Next j
Next q
Cells(m + 2, 1).Resize(m, m) = a