+ Reply to Thread
Results 1 to 9 of 9

Convert a string to a TextBox name that VBA recognises

  1. #1
    Registered User
    Join Date
    04-28-2014
    Location
    Woodbridge VA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Convert a string to a TextBox name that VBA recognises

    ' I want to loop through TextBoxes and get their values
    ' In this simple test case, to insert them in spreadsheet cells A1 and A2

    ' VBA does nor recognize a string as a Textbox name and I have not been
    ' able to find a way to make this work.

    ' Any help would be very much appreciated!


    Please Login or Register  to view this content.
    Last edited by Leith Ross; 12-24-2014 at 05:49 PM. Reason: Added Code Tags

  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: Convert a string to a TextBox name that VBA recognises

    Where are the textboxes located?

    PS Can you add code tags when posting code?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    04-28-2014
    Location
    Woodbridge VA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Convert a string to a TextBox name that VBA recognises

    In Sheet1 right now, later in a UserForm

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Ian Fraser; 12-24-2014 at 03:14 PM.

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

    Re: Convert a string to a TextBox name that VBA recognises

    You can use a string to refer to a control on a sheet or userform but the syntax isn't the same for both.

    Furthermore, if they are on a sheet the syntax depends on which type of control they are, Forms or ActiveX.

    Can you upload an example workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    PS The colours are because you've used the tags for PHP code, not exactly quite sure what each colour represents.

    If you use 'standard' code tags you won't get the colours.

  5. #5
    Registered User
    Join Date
    04-28-2014
    Location
    Woodbridge VA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Convert a string to a TextBox name that VBA recognises

    Norie,

    the spreadsheet is attached to the 10:55am post above.

    I'm using ActiveX controls. Got rid of the colored code

    Thanks for your help!

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Convert a string to a TextBox name that VBA recognises



    Just read this thread

  7. #7
    Registered User
    Join Date
    04-28-2014
    Location
    Woodbridge VA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Convert a string to a TextBox name that VBA recognises

    Marc,

    when I add "Controls" to the line Range(strRange).Value = Controls("TextBox" & CStr(iCount)).Value

    I get an error message: "Compile Error Sub or Function not defined" and the word "Controls" is highlighted.

  8. #8
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Convert a string to a TextBox name that VBA recognises

    Hi Ian,

    The following routines will display output in the Immediate Window (CTRL G) in the debugger.

    Try this code for Active X controls:
    Please Login or Register  to view this content.
    Use the following for a UserForm:
    Please Login or Register  to view this content.
    Lewis

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Convert a string to a TextBox name that VBA recognises

    Hello Ian Fraser,

    Here is the corrected and working macro code.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ 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. add a string of locked text to vba textbox based on entry in the same textbox
    By yoursamrit2000 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-21-2014, 11:48 PM
  2. help to convert textbox value to negative based on another textbox value
    By lewisw in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 03-19-2014, 11:00 AM
  3. Replies: 3
    Last Post: 05-07-2012, 09:46 PM
  4. convert textbox value from string to either single or double numeric data type
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-08-2011, 06:40 PM
  5. Userform: Convert textbox value from string to type long
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-04-2011, 11:38 AM

Tags for this Thread

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