+ Reply to Thread
Results 1 to 9 of 9

Change text in label - object required?

  1. #1
    Registered User
    Join Date
    10-23-2008
    Location
    Sweden
    Posts
    92

    Change text in label - object required?

    Hello,

    I'm trying to change the text in a label called NameLabel1 with the code NameLabel1.Caption = "hello"
    However it fails with the message "object required".

    How does one change the text properly?

    /Johan

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Change text in label - object required?

    Johan

    That is the correct code to set the caption of a Label.

    Where is the label located and where is the code located?
    If posting code please use code tags, see here.

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Change text in label - object required?

    Can we assume the label is on the worksheet rather than a userform?
    Is the label from the Forms or ActiveX set of controls?
    Cheers
    Andy
    www.andypope.info

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Change text in label - object required?

    If the label is situated on a worksheet the code has to be in the worksheetmodule rather then in a standard module. Otherwise you will also have to refer to the worksheet the label is on.
    e.g.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  5. #5
    Registered User
    Join Date
    10-23-2008
    Location
    Sweden
    Posts
    92

    Re: Change text in label - object required?

    The label is located on the worksheet and the code is in a module for the workbook. The label is from the Forms.

  6. #6
    Registered User
    Join Date
    10-23-2008
    Location
    Sweden
    Posts
    92

    Re: Change text in label - object required?

    I tried to refer to the worksheet as well (Blad3.NameLabel1.Caption = "hello") but then I get "Compile Error - Method or data member not found"

    I'm starting to think there is something wrong with the label itself, as far as I can see it's called "NameLabel1"
    2017-08-15 10_01_02-track.xlsm - Excel.jpg
    Last edited by johandenver; 08-15-2017 at 04:04 AM.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Change text in label - object required?

    Try this.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-23-2008
    Location
    Sweden
    Posts
    92

    Re: Change text in label - object required?

    Thanks, that worked perfectly.

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Change text in label - object required?

    Like this.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Change userform label height without changing label width
    By vamosj in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-16-2015, 01:08 PM
  2. Replies: 2
    Last Post: 08-07-2014, 03:14 PM
  3. change column label text to headers by scroll page
    By jc2398 in forum Excel General
    Replies: 3
    Last Post: 06-16-2014, 04:09 AM
  4. Replies: 3
    Last Post: 10-02-2012, 06:17 AM
  5. Name.Object (Error Object Required)
    By dssrun209 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-12-2010, 01:38 PM
  6. Change label text on a chart sheet
    By slide in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 03-05-2008, 11:30 AM
  7. [SOLVED] How change dimensions of data label text box in pie chart?
    By Gouden Willem in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 03-07-2006, 08:20 AM

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