Thread: Loop help
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_5_] Dave Peterson[_5_] is offline
external usenet poster
 
Posts: 1,758
Default Loop help

Maybe....

'copy the data to the database
With ws
.Cells(iRow, 1).Value = Me.txt1.Value
.Cells(iRow, 2).Value = Me.txt2.Value
.Cells(iRow, 3).Value = Me.txtStart.Value
.Range(.Cells(iRow, Me.txtStart.Value + 5), _
.Cells(iRow, Me.txtStop.Value + 5)).Value = Me.txt3.Value
End With

Is it me.txt1 or me.tx1t???



Henry wrote:

Hi
I am new to VBA and am trying to learn by disecting existing code and
appying to my projects. Part of the code that I have written so far is:

Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet

Set ws = Worksheets("Data")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row

Some Code

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.tx1t.Value
ws.Cells(iRow, 2).Value = Me.txt2.Value
ws.Cells(iRow, 3).Value = Me.txtStart.Value
ws.Cells(iRow, Me.txtStart.Value + 5).Value = Me.txt3.Value

'clear the data
Me.txt1.Value = ""
Me.txt2.Value = ""
Me.txtStart.Value = ""
Me.txt3.Value = ""

End Sub

This copies the txt3 value to the correct cell. What I would like to do is
add a txtStop and have the code loop through and copy to all of the cells in
irow in the columns from txtStart +5 to txtStop+5.
Thanks


--

Dave Peterson