Array problems

  • Thread starter Thread starter KneeDown2Up
  • Start date Start date
K

KneeDown2Up

I have a number of text boxes (ibox1 - ibox28) all holding data inputed via a
userform. To capture this data I potentially (with my knowledge) need this;


Sheet19.Cells(5, c) = Sheet19.Cells(5, c) + ibox1.Value
Sheet19.Cells(6, c) = Sheet19.Cells(5, c) + ibox2.Value
...and so on.

I would like to be able to run this within a 'For/Next' loop but keep coming
up against problems.

For i = 1 to 28
Sheet19.Cells(5, c) = Sheet19.Cells(5, c) + ibox(i).Value
next i

Why is this? What can I do to make this principle work?

Any help appreciated, thanks.
 
First of all, I am assuming you made a typo with:

Sheet19.Cells(5, c) = Sheet19.Cells(5, c) + ibox1.Value
Sheet19.Cells(6, c) = Sheet19.Cells(5, c) + ibox2.Value

and the second line should have been

Sheet19.Cells(6, c) = Sheet19.Cells(6, c) + ibox2.Value

If so, this should work:

For i = 1 to 28
Sheet19.Cells(i + 4, c) = Sheet19.Cells(i + 4, c) + ibox(i).Value
next i
 
For i = 1 To 10
Set bx = ActiveSheet.OLEObjects("TextBox" & i)
TextData = bx.Object.Text
Next i
 
Should be: For i = 1 to 28
Sheet19.Cells(i + 4, c) = Sheet19.Cells(i + 4, c) +
(ibox & i).Value
next i
 
Thanks JL - nearly there although I can't quite get this to work. It would
seem the ibox variable isn't carrying the value entered by the user. It just
inputs 1 - 28 (on each loop) and the ibox is empty. When I put the .value to
the ibox it comes up with an 'expected: end of statement' message. I tried
declaring each of the iboxes (ibox1, ibox2) etc in the 'Declarations' part
but to no avail (another error message).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top