+ 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 CJ-22, try this
    Private Sub CommandButton1_Click()
        
        Dim ws As Worksheet
        Dim rng As Range
        Dim lblStr As String
        
        lblStr = Me.Label1.Caption
        Set ws = Worksheets("Sheet 1")
        Set rng = ws.Range("J" & ws.Cells(ws.Rows.Count, 10).End(xlUp).Offset(1, 0).Row)
        With rng
            .ClearFormats
            .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 = lblStr
            .Borders.LineStyle = xlContinuous
        End With
    
    End Sub
    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

    Thanks so much for the help. This is working really well. There are two issues that I was hoping you can help me address.

    1. If the value in Label1 is less than 1 minute then the minutes are placed where the hours go, the seconds are placed where the minutes go, and the decimals are placed where the seconds go. If the value is more than one minute it works great. I have no idea how to fix this and was hoping you could help.

    2. Is there any way to have this move to the right instead of down. For example, once the input button is clicked it places the values in J7:L7. The next time input is clicked the values go to J8:L8. I would rather it be placed in M7:O7.

    Thanks again for all the help.

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

    Re: Macro to paste value from userform label

    Bump. Any ideas?

  4. #4
    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

    Quote Originally Posted by CJ-22 View Post
    1. If the value in Label1 is less than 1 minute then the minutes are placed where the hours go, the seconds are placed where the minutes go, and the decimals are placed where the seconds go. If the value is more than one minute it works great. I have no idea how to fix this and was hoping you could help.
    I really don't understand this, you want to change the data output from say 00:00:58.12 to 00:58:12? Under what circumstance would this be required? How exactly is the label being populated? Is it originally a date format?

+ 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