+ Reply to Thread
Results 1 to 3 of 3

Which loop to use

Hybrid View

  1. #1
    Registered User
    Join Date
    07-05-2005
    Posts
    11

    Question Which loop to use

    Here is my question. I have a user form with 12 textboxes, each named textbox1-textbox12. I want the data to go from the user form to a sheet. I try to make the process quicker by using a for loop. For example:

    For k=1 to 12
    j=k+1
    ActiveCell.Offset(k,0).Value = TextBoxj.value 'Here is where error is highlighted
    Next k

    However, everytime I try this I get the same error saying "Object required". The only way I can get this to work is by individualy giving the value of the cell the value of the textbox, for example:
    ActiveCell.Offset(1,0).Value = TextBox2.value 'I do this for all 12 textboxes.

    Is there a way to loop this so I don't have to right each line of code? Thanks for your help in advance.

    theguz

  2. #2
    FSt1
    Guest

    RE: Which loop to use

    hi,
    i think it doesn't know what j is. have you declared it?

    regards
    FSt1

    "theguz" wrote:

    >
    > Here is my question. I have a user form with 12 textboxes, each named
    > textbox1-textbox12. I want the data to go from the user form to a
    > sheet. I try to make the process quicker by using a for loop. For
    > example:
    >
    > For k=1 to 12
    > j=k+1
    > ActiveCell.Offset(k,0).Value = TextBoxj.value 'Here is where error
    > is highlighted
    > Next k
    >
    > However, everytime I try this I get the same error saying "Object
    > required". The only way I can get this to work is by individualy
    > giving the value of the cell the value of the textbox, for example:
    > ActiveCell.Offset(1,0).Value = TextBox2.value 'I do this for all 12
    > textboxes.
    >
    > Is there a way to loop this so I don't have to right each line of code?
    > Thanks for your help in advance.
    >
    > theguz
    >
    >
    > --
    > theguz
    > ------------------------------------------------------------------------
    > theguz's Profile: http://www.excelforum.com/member.php...o&userid=24918
    > View this thread: http://www.excelforum.com/showthread...hreadid=393366
    >
    >


  3. #3
    Duke Carey
    Guest

    RE: Which loop to use

    For j=1 to 12
    ActiveCell.Offset(j-1,0).Value = formname.controls("TextBox"& j).value
    Next j


    "theguz" wrote:

    >
    > Here is my question. I have a user form with 12 textboxes, each named
    > textbox1-textbox12. I want the data to go from the user form to a
    > sheet. I try to make the process quicker by using a for loop. For
    > example:
    >
    > For k=1 to 12
    > j=k+1
    > ActiveCell.Offset(k,0).Value = TextBoxj.value 'Here is where error
    > is highlighted
    > Next k
    >
    > However, everytime I try this I get the same error saying "Object
    > required". The only way I can get this to work is by individualy
    > giving the value of the cell the value of the textbox, for example:
    > ActiveCell.Offset(1,0).Value = TextBox2.value 'I do this for all 12
    > textboxes.
    >
    > Is there a way to loop this so I don't have to right each line of code?
    > Thanks for your help in advance.
    >
    > theguz
    >
    >
    > --
    > theguz
    > ------------------------------------------------------------------------
    > theguz's Profile: http://www.excelforum.com/member.php...o&userid=24918
    > View this thread: http://www.excelforum.com/showthread...hreadid=393366
    >
    >


+ 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