Consulting

Results 1 to 4 of 4

Thread: Solved: Updating label caption

  1. #1

    Solved: Updating label caption

    I'm not sure if this is the correct method to ask an Excel question - but here goes.

    I have a problem where I want to update many label captions (text) from user inputted data in one single macro and see the results as the data is entered. I cannot see the results on the screen until the macro finishes even though the text has changed. I have "boiled the issue down to this macro":-

    [vba]
    Sub test()
    Worksheets("sheet1").Label1.Caption = "original box 1"
    Worksheets("sheet1").Label2.Caption = "original box 2"
    answer = InputBox(prompt:="Enter text for 1st label", ypos:=6000, xpos:=4000)
    Worksheets("sheet1").Label1.Caption = answer
    answer2 = InputBox(prompt:="Enter text for 2nd label", ypos:=6000, xpos:=4000)
    Worksheets("sheet1").Label2.Caption = answer2
    MsgBox "The value in label 1 is " & Worksheets("sheet1").Label1.Caption
    End Sub
    [/vba]
    Many thanks in advance..
    Last edited by mdmackillop; 05-16-2006 at 12:22 AM. Reason: Moved to Excel forum and VBA tags added

  2. #2
    MS Excel MVP VBAX Mentor Andy Pope's Avatar
    Joined
    May 2004
    Location
    Essex, England
    Posts
    344
    Location
    Hi,

    DoEvents will normally handle any updating. But for some reason I do not understand a double DoEvents is required to update your controlbox labels.
    [vba]Sub test()
    Dim answer, answer2

    With Worksheets("sheet1")
    .Label1.Caption = "original box 1"
    .Label2.Caption = "original box 2"
    DoEvents
    DoEvents

    answer = InputBox(prompt:="Enter text for 1st label", ypos:=6000, xpos:=4000)
    .Label1.Caption = answer
    DoEvents
    DoEvents

    answer2 = InputBox(prompt:="Enter text for 2nd label", ypos:=6000, xpos:=4000)
    .Label2.Caption = answer2
    DoEvents
    DoEvents
    MsgBox "The value in label 1 is " & .Label1.Caption
    End With
    End Sub[/vba]
    Cheers
    Andy

  3. #3
    Hi Andy,
    This works great.
    Regards from "down under"

  4. #4
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Hi and welcome!

    I've marked your thread as "Solved" - in future, once you have the solution to your question go to the "Thread Tools" at the top of the screen to do this.

    It's always nice to see another Aussie join the board

Posting Permissions

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