Consulting

Results 1 to 3 of 3

Thread: Userform Help

  1. #1
    VBAX Newbie
    Joined
    Oct 2016
    Posts
    2
    Location

    Userform Help

    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?

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Here's a simple demo of using a userform to capture data and use it
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Newbie
    Joined
    Oct 2016
    Posts
    2
    Location
    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
    Last edited by Bob Phillips; 10-11-2016 at 02:41 AM. Reason: Tidied-up code

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •