Consulting

Results 1 to 8 of 8

Thread: UserForm that Stays Visible on Screen When Scrolling

  1. #1
    VBAX Contributor
    Joined
    Nov 2015
    Location
    Minnesota
    Posts
    101
    Location

    UserForm that Stays Visible on Screen When Scrolling

    I have never used a UserForm before so I am looking for some help. I want the form to stay displayed on the upper right hand corner of the screen, even when the user is scolling up, down, left or right in the worksheet. I only want this displayed on one worksheet in my workbook. The form should display as a scrolling list and update on each selection change. I have code below that gets me my results without using any form (but it doesn't move when scrolling). Some of the code will need to be modified to work in the form. For instance, I obviously do not want data to be printed on Sheets("WI").Cells(1150, 7). I want it in the form.

    There may be a better way to code all of this. I feel like it may slow down the workbook quite a bit so I would appreciate the help on that too. The idea behind the code is: I have a large data table (70,000 rows), and I want to display every item that has the value of Sheets("WI").Cells(Selection.Row, 2) in column 2 of the data table. That's all I'm trying to do. It's basically a filter.

    Sorry, I don't have a file to share.


    Sub WI_List()
    
    CellLoopR = Selection.Row
    
    Do
        Sheets("WI").Cells(1150, 7) = Cells(CellLoopR, 2).End(xlUp)
        CellLoopR = Cells(CellLoopR, 2).End(xlUp).Row
    Loop While Len(Cells(CellLoopR, 2)) <= 3
    
    Sheets("Code Testing").Range("H1").FormulaArray = "=MATCH(""" & Sheets("WI").Cells(1150, 7) & """,Table3[WI],0)+1"
    rr = Sheets("Code Testing").Range("H1")
    
    For i = 0 To WorksheetFunction.CountIf([Table3[WI]], Sheets("WI").Cells(1150, 7)) - 1
    
        With Sheets("Sheet1")
        'With Sheets("Oracle Item Numbers")
            Range(.Cells(rr, 2), .Cells(.Range("A1").End(xlDown).Row, 2)).Name = "WI_Range"
        End With
    
    Sheets("Code Testing").Range("H1").FormulaArray = "=MATCH(""" & Sheets("WI").Cells(1150, 7) & """,WI_Range,0)"
    
    Cells(1150 + 1 + i, 7) = Sheets("Sheet1").Cells(Sheets("Code Testing").Range("H1") + rr - 1, 1)
    'Cells(1150 + 1 + i, 7) = Sheets("Oracle Item Numbers").Cells(Sheets("Code Testing").Range("G1") + rr - 1, 1)
    
    rr = rr + Sheets("Code Testing").Range("H1")
        
    Next i
    
    
    End Sub

  2. #2
    Would this do it?
    Private Sub Workbook_open() 
        UserForm1.Show vbModeless 
    End Sub

  3. #3
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    That would put it in the center. For the top right corner then something like this:

    [CODESub ScratchMacro()
    With UserForm1
    .StartUpPosition = 0
    .Left = Application.Left + Application.Width - .Width - (.Width - .InsideWidth)
    .Top = Application.Top + (.Height - .InsideHeight)
    .Show vbModeless
    End With
    lbl_Exit:
    Exit Sub
    End Sub][/CODE]
    Greg

    Visit my website: http://gregmaxey.com

  4. #4
    VBAX Contributor
    Joined
    Nov 2015
    Location
    Minnesota
    Posts
    101
    Location
    Thank you for the responses. However, Neither of them put the form in the upper right corner. I have 2 monitors (not sure if that makes a difference).
    I am more concerned with getting the functionality to work, rather than the position of the form at this point. So I would really appreciate the help with that.

  5. #5
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    I couldn't open your sample file.....

  6. #6
    VBAX Contributor
    Joined
    Nov 2015
    Location
    Minnesota
    Posts
    101
    Location
    I just have this little example.

    VBA Help.xlsm

  7. #7
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    See attached.
    Userform appears on sheet activation.
    Move the userform to where you like (it can be positioned differently on showing).
    Attached Files Attached Files
    Last edited by p45cal; 05-11-2016 at 09:50 AM.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  8. #8
    VBAX Contributor
    Joined
    Nov 2015
    Location
    Minnesota
    Posts
    101
    Location
    p45cal, that should do the trick! I appreciate the help!

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
  •