Variable in a textbox reference?

J

Jacob

is it possible to put a variable in a reference to a textbox? here is
my code:

For i = 1 To loads
Cells(8 + i, 3).Value = TextBoxPi.Value * 1.6
Next i

I have textboxes labeled TextBoxP1, TextBoxP2, etc. and I want to get
there values into worksheet cells only for a certain number (loads) of
textboxes. so I'm trying to increment it by i. I assume my code will
not work, but I'm wondering how this can be done. Thanks.
 
D

Dave Peterson

These are textboxes in a userform?

if yes:

Option Explicit
Private Sub CommandButton1_Click()
Dim loads As Long
Dim i As Long
loads = 3
For i = 1 To loads
Worksheets("sheet1").Cells(8 + i, 3).Value _
= Me.Controls("TextBoxP" & i).Value * 1.6
Next i
End Sub
 
J

Jacob

that's what i needed. Thank you!


Dave said:
These are textboxes in a userform?

if yes:

Option Explicit
Private Sub CommandButton1_Click()
Dim loads As Long
Dim i As Long
loads = 3
For i = 1 To loads
Worksheets("sheet1").Cells(8 + i, 3).Value _
= Me.Controls("TextBoxP" & i).Value * 1.6
Next i
End Sub
 

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

Top