+ Reply to Thread
Results 1 to 15 of 15

Macro to paste value from userform label

Hybrid View

  1. #1
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Macro to paste value from userform label

    Hi, you'll have to amend this code to however your form is set up ie whether it's called with a button but for my testing purposes I used the form initialization event.
    Private Sub UserForm_Initialize()
    
        Dim ws As Worksheet
        Dim rng As Range
        Dim lblStr As String
        Me.Label1.Caption = "04:32:56"
        lblStr = Me.Label1.Caption
        Set ws = Worksheets("Sheet1")
        Set rng = ws.Range("J7")
        With rng
            .Value = Left(lblStr, 2)
            lblStr = Replace(lblStr, Left(lblStr, 3), "")
            .Offset(0, 1).Value = Left(lblStr, 2)
            lblStr = Replace(lblStr, Left(lblStr, 3), "")
            .Offset(0, 2).Value = Left(lblStr, 2)
            lblStr = ""
        End With
        
    End Sub
    There's no doubt other ways to do this but I inserted just string values into the cells, not time formatted. Give it a try and let me know if they have to maintain the time formats.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  2. #2
    Forum Contributor
    Join Date
    12-16-2004
    Posts
    125

    Re: Macro to paste value from userform label

    Hi Mordred,

    Thanks for the reply. This almost does what I need it to do. It places the value 4 in J7, 32 in K7, and 56 in L7, which are the numbers in your code, but it does not use the value from the label. The label changes frequently like a clock and I need it to place these values from the label. I also noticed that it did not have the decimal values with the seconds. Can the decimals be added to the second value?
    Thanks again for the help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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