Copy test to form

  • Thread starter Thread starter SMERTZ
  • Start date Start date
S

SMERTZ

What is the best way to copy data from a row, lets say row 2 cells 1 thru 15
to 15 text boxes on a form?

txt1= activeRow column 1
txt2=activeRow column 2
txt3 = active row column 3

You get the idea: Most of the data is Text, but there are a few dates in
the cells
 
one way:

For i= 1 to 15
me.controls("txt" & i).value=Cells(activerow,i)
next i

if text boxes are TXT1 to TXT15

HTH
 
Private Sub UserForm_Initialize()
Dim myCtrl As Control
For Each myCtrl In Me.Controls
If Left(myCtrl.Name, 3) = "txt" Then myCtrl.Value = Cells(2,
Val(Mid(myCtrl.Name, 4))).Value
Next
End Sub
 
If they have names without a constant prefix e.g TXT...., then have any array
of text box names and compare with "control names". nth element in array
corresponds to nth column . You could use MATCH function to compare.
 

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