PDA

View Full Version : Solved: Updating label caption



thebretts
05-15-2006, 11:22 PM
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":-


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

Many thanks in advance..

Andy Pope
05-16-2006, 12:55 AM
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.
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

thebretts
05-17-2006, 03:49 AM
Hi Andy,
This works great.
Regards from "down under"

geekgirlau
05-18-2006, 01:22 AM
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 :beerchug: