Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 5th, 2008, 04:11 AM
Registered User
 
Join Date: Sep 2008
Location: South Holland, IL, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel VB : How to change Label Caption

I have one button and 10 labels stacked in a column in my worksheet.
Now when I press the button each time, it clears the caption of the last label from the bottom of the stack that has some caption displayed.
My work sheet looks as below.

Label caption 1
Label caption 2
Label caption 3
Label caption 4
Label caption 5
Label blank
Label blank
Label blank


5 <- this cell below the above label stack holds cell pointing at the last Label having Caption "Label caption 5"

[Button]<- Pressing this button each time would change a Label's caption from "Label Caption #" to "Label blank".

Can any one help me with this?

pap
Reply With Quote
  #2 (permalink)  
Old September 22nd, 2008, 04:46 PM
Friend of Wrox
Points: 513, Level: 8
Points: 513, Level: 8 Points: 513, Level: 8 Points: 513, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2007
Location: Davenport, IA, USA.
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts
Default

This an exercise for you? Why not just have 1 label and rename the caption each time based on previous name? How are you tracking the label number it is on? How would the labels reset?
Assuming they're named Caption_Labelx where X is 1 thru 10 and it's unknown which level is currently blank then the code should be something like this:
----------------------------------------------------
  Dim iCount As Integer, oSheet As Worksheet
  Set oSheet = ActiveWorkbook.ActiveSheet
  Do While iCount < 10 And oSheet.OLEObjects("Caption_Label" & 10 - iCount).Object.Caption = "Label blank"
    iCount = iCount + 1
  Loop
  If iCount < 10 _
    Then oSheet.OLEObjects("Caption_Label" & 10 - iCount).Object.Caption = "Label blank" _
    Else MsgBox "All Label captions set to 'Label blank'", , "Notification"
----------------------------------------------------

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Caption HtmlInputFile but it doest not upl. Israr HTML Code Clinic 1 April 25th, 2008 04:08 AM
Change button caption on continuous subform PeregrinTook Access VBA 2 April 16th, 2007 05:16 PM
CAPTION OF ACCESS DB IN VB akash VB How-To 5 March 8th, 2007 10:01 PM
Change Caption HtmlInputFile Israr ASP.NET 1.0 and 1.1 Professional 4 November 8th, 2006 01:32 AM
saving changes to label caption Loralee Access 5 January 6th, 2006 08:53 PM



All times are GMT -4. The time now is 11:10 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.