Variable coding

D

Dave

I have programmed an excel "form" to dump data entry into a "sheet" in the
same work book.

On the save button:
Worksheets("Successor").Range("b2").Value = cboPositionID1
Worksheets("Successor").Range("c2").Value = cboReadiness1
Worksheets("Successor").Range("d2").Value = txtDev1

On the form initulitazion:
Me.cboPositionID1.Value = Worksheets("Successor").Range("b2").Value
Me.cboReadiness1.Value = Worksheets("Successor").Range("c2").Value
Me.txtDev1.Value = Worksheets("Successor").Range("d2").Value

These are 3 fields for ONE row on the form.
However, I need to make 20 rows with the same 3 fields and they would dump
in to successive rows

Example
Row 1 field1
Worksheets("Successor").Range("b2").Value = cboPositionID1

Row 2 field 1
Worksheets("Successor").Range("b3").Value = cboPositionID2

And so on.
So - not too hard to program but also way more code then necessary.

Something more elegant would be to have variables for:
Cell row number
&
Field number (cboPositionID1 or 2 or 3....)

Example:
Worksheets("Successor").Range("bVarialble").Value = cboPositionIDVariable

Can someone help me write that?

Hope I have explained what I need

Any help here will be appreciated.

Thanks in advance

dave
 
B

Bob Phillips

For i = 1 To 20
Worksheets("Successor").Range("b" & i + 1).Value =
Me.Controls("cboPositionID" & i).Value
Worksheets("Successor").Range("c" & i + 1).Value =
Me.Controls("cboReadiness" & i).Value
Worksheets("Successor").Range("d" & i + 1).Value =
Me.Controls("txtDev" & i).Text
Next i

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

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