+ Reply to Thread
Results 1 to 7 of 7

Looping through txtboxes, cboboxes and taking values

  1. #1
    Registered User
    Join Date
    10-13-2008
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    85

    Looping through txtboxes, cboboxes and taking values

    I would actually be really interested in finding an answer on this one too.

    For most things I use the For function but I find myself repeating lines over again. Eg I have txtboxes for each month and the contents are either user defined or looked up from a sheet. But now I want to get the contents back to a different sheet. Instead of repeating multiple lines of code, I'd prefer to use a For Each "txtbox". They've all got essentially the same name...F1, F2, F3 etc.

    Is there anything I can do to make it simpler...and cut down my code by half

    Thanks!
    Last edited by Leith Ross; 09-15-2011 at 01:11 AM. Reason: Added Link

  2. #2
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Looping through txtboxes, cboboxes and taking values

    Hi benno87,

    Work with following code, I hope it is possible to adapt it to your project
    Please Login or Register  to view this content.
    Best Regards
    MaczaQ

  3. #3
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Looping through txtboxes, cboboxes and taking values

    If you have used a naming convention then you can also use that in your code:
    Please Login or Register  to view this content.
    for example.
    Remember what the dormouse said
    Feed your head

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Looping through txtboxes, cboboxes and taking values

    If you have used a naming convention then you can also use that in your code:
    Please Login or Register  to view this content.
    for example.

  5. #5
    Registered User
    Join Date
    10-13-2008
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    85

    Re: Looping through txtboxes, cboboxes and taking values

    Thanks very much for your replies. I've also just realised that my code is different per txtbox too. eg each cell refers to a different column in a sheet.
    Please Login or Register  to view this content.
    Is there someway to incorporate an R1C1 reference into this sort of code, so then it can just be RCx+1, +2, +3 etc, relevant to the Fx number of course?

    Also what part does the "debug.print" function play? I've seen it before but never used it as I haven't understood its purpose.

    Thanks heaps guys, much appreciated!
    Benno
    Last edited by benno87; 09-15-2011 at 08:25 PM. Reason: Changed code

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Looping through txtboxes, cboboxes and taking values

    Debug.Print just outputs values to the Immediate window.
    You could use a loop like:
    Please Login or Register  to view this content.

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Looping through txtboxes, cboboxes and taking values

    or
    Please Login or Register  to view this content.
    Last edited by snb; 09-16-2011 at 03:21 AM.



+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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