+ Reply to Thread
Results 1 to 12 of 12

Create Vertical Scrolling Text in UserForm

Hybrid View

  1. #1
    Registered User
    Join Date
    03-24-2020
    Location
    India
    MS-Off Ver
    2013
    Posts
    6

    Post Create Vertical Scrolling Text in UserForm

    Trying to create a userform in VBA excel where in the text can be scrolled vertically to show what I add in specific cells of excel. I am using version 2016 of excel.

    Have taken VBA code from google which is given below:

    Private Sub UserForm_Initialize()
    Me.Label1.Caption = Sheet1.Range("b4").Value
    Me.Label2.Caption = Sheet1.Range("E9").Value & vbCrLf & vbCrLf & Sheet1.Range("E10").Value & vbCrLf & vbCrLf & Sheet1.Range("E11").Value & vbCrLf & vbCrLf & Sheet1.Range("E12").Value & vbCrLf & vbCrLf & Sheet1.Range("E13").Value
    Me.Label2.Top = Me.Height
    End Sub

    This part of code works well when I comment "Me.Label2.Top = Me.Height" this part of the code.

    The second part of the code is for Vertical Scroll where in the scrolling happens however the loop where in the scrolling has to be repeated is not working. Code given below:

    Sub verti_scroll()
    Call UserForm1.Show(vbModeless)
    
    Do
    i = UserForm1.Height - 42
    
    Do
    i = i - 1
        DoEvents
        For a = i To 5000000
        a = a + 1
        Next
        UserForm1.Label2.Top = i
        If i = 100 Then GoTo Nextz
        
    Loop
    Nextz:
    x = x + 1
    If x = 2 Then GoTo nextx
    Loop
    nextx:
    End Sub
    Attached Files Attached Files
    Last edited by AliGW; 04-27-2024 at 01:20 AM.

  2. #2
    Registered User
    Join Date
    03-24-2020
    Location
    India
    MS-Off Ver
    2013
    Posts
    6

    Re: Create Vertical Scrolling Text in UserForm

    Hello All,

    Can any body look into this and suggest where to change code. Your help in this regard would be appreciated. Thanks

  3. #3
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,079

    Re: Create Vertical Scrolling Text in UserForm

    Does this work for you?
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    03-24-2020
    Location
    India
    MS-Off Ver
    2013
    Posts
    6

    Re: Create Vertical Scrolling Text in UserForm

    Thanks so much ByteMarks. Works perfectly as I wanted. Really Appreciate the timely help you have given me. Appreciate it. Thanks

  5. #5
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,079

    Re: Create Vertical Scrolling Text in UserForm

    You're welcome.

  6. #6
    Valued Forum Contributor MikeVol's Avatar
    Join Date
    12-30-2020
    Location
    Odessa / Ukraine
    MS-Off Ver
    MSO Prof Plus 2021 x64 (En)
    Posts
    499

    Re: Create Vertical Scrolling Text in UserForm

    NOTE: As the original poster/owner, only you can mark your thread as SOLVED (Thread Tools above Post #1).
    You can say "Thanks" in your thread to everyone who offered to help you.
    You can also reward them by clicking * "Add Reputation" under their username on the left.
    With Regards, MikeVol.

  7. #7
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,542

    Re: Create Vertical Scrolling Text in UserForm

    Since the slowdown loop (For i=1 To 5M) heats up to the red the processor and such a loop on different computers will cause scrolling at different speeds I propose minor changes:
    Instead of
        For i = 1 To 5000000
            i = i + 1
        Next
    type
        Sleep 20
    and at the beginning of Module1 insert the API function declaration:
    Option Explicit
    
    #If VBA7 Then
        Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
        'For 64-Bit versions of Excel
    #Else
        Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
        'For 32-Bit versions of Excel
    #End If
    You can control the scrolling speed by changing the Sleep value.


    Below is a dynamic version of this task.
    Full code in the UserForm module:
    Option Explicit
    
    Dim blnQuit As Boolean
    
    
    Private Sub UserForm_Initialize()
        Dim i As Long
        Dim strTxt As Variant
    
        With Sheet1
            Me.Label1.Caption = .Range("B4").Value
            
            'It is assumed that at least two cells are filled (E9 and E10)
            For i = 9 To .Range("E9").End(xlDown).Row
                strTxt = strTxt & (.Cells(i, "E").Value & String(2, vbLf))
            Next i
        End With
    
            strTxt = Left(strTxt, Len(strTxt) - 2)
    
        With Me.Label2
            .Width = Me.InsideWidth
            .Left = 0
            .Caption = strTxt
            .AutoSize = True
            .AutoSize = False
            'centered horizontally
            .Left = (Me.Width - .Width) / 2
        End With
    
    End Sub
    
    
    Private Sub UserForm_Activate()
        Dim snH As Single
        Dim snEnd As Single
        Dim snStart As Single
    
        snEnd = -Me.Label2.Height
        snStart = Me.InsideHeight
    
        snH = snStart
        Me.Label2.Top = snH
    
        Do While blnQuit = False
    
            If snH <= snEnd Then
                snH = snStart
            End If
            snH = snH - 0.75
            Me.Label2.Top = snH
    
            Sleep 1
            DoEvents
        Loop
    
    End Sub
    
    
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
        blnQuit = True
    End Sub
    Artik

  8. #8
    Registered User
    Join Date
    03-24-2020
    Location
    India
    MS-Off Ver
    2013
    Posts
    6

    Re: Create Vertical Scrolling Text in UserForm

    Thanks so much Artik. Really appreciate the help. Thanks a lot.

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,040

    Re: Create Vertical Scrolling Text in UserForm

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not told us about this. You are required to do so. Cross-posts are allowed but you must provide a link to your posts on other sites.

    Please see Forum Rule #7 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important: https://excelguru.ca/a-message-to-forum-cross-posters/

    (Note: this requirement is not optional. As you are new here, I shall do it for you this time: https://www.mrexcel.com/board/thread...rform.1257901/)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  10. #10
    Registered User
    Join Date
    03-24-2020
    Location
    India
    MS-Off Ver
    2013
    Posts
    6

    Re: Create Vertical Scrolling Text in UserForm

    Sure Ali. Was not aware regarding the cross posting. Would surely keep this in mind from next time onwards.

    Thanks

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,040

    Re: Create Vertical Scrolling Text in UserForm

    But, despite my message, you failed to declare this one : https://stackoverflow.com/questions/...xt-in-userform

    Make sure you comply with our rules in future, please.

  12. #12
    Registered User
    Join Date
    03-24-2020
    Location
    India
    MS-Off Ver
    2013
    Posts
    6

    Re: Create Vertical Scrolling Text in UserForm

    Surely. Would take care of the rules. Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. scrolling down vertical bar automatically
    By mark_neil2 in forum Excel General
    Replies: 3
    Last Post: 12-22-2015, 09:20 AM
  2. [SOLVED] Create A UserForm that tracks points and allows scrolling and use of worksheet
    By ChemistB in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-05-2015, 12:13 PM
  3. Freeze column so always on top vertical scrolling?
    By Emma Frost in forum Excel General
    Replies: 4
    Last Post: 03-31-2015, 10:58 AM
  4. Excel 2007 : Vertical Scrolling in Excel
    By mdgajes in forum Excel General
    Replies: 1
    Last Post: 12-16-2011, 11:39 AM
  5. Vertical scrolling chart?
    By PhilT in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 07-20-2007, 08:48 AM
  6. [SOLVED] how do I create a single row of vertical text?
    By computermomma in forum Excel General
    Replies: 1
    Last Post: 09-17-2005, 11:05 AM
  7. How to create a text scrolling window?
    By Rickk in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 01-28-2005, 11:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1