View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Variable in a textbox reference?

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

Jacob wrote:

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.


--

Dave Peterson