![]() |
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 -- theguz ------------------------------------------------------------------------ theguz's Profile: http://www.excelforum.com/member.php...o&userid=24918 View this thread: http://www.excelforum.com/showthread...hreadid=393366 |
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 |
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 |
All times are GMT +1. The time now is 11:58 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com