Thread: Next column
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Next column

You have hard coded column references - what determines the next column.
You are working in column A through E of the current row. What determines
that you want to look at a different column rather than D and/or E. Which
column do you want to look at?

Do While Len(cells(r,i).formula) 0 And r < 43
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("FieldNameN") = Range("B3").Value
.Fields("FieldNameN") = Range("e17").Text
.Fields("FieldNameN") = Range("A" & r).Value
.Fields("FieldNameN") = Range("B" & r).Value
.Fields("FieldNameN") = Range("C" & r).Value
' After here I would like to change the column to the next column
.Fields("FieldNameN") = Range("D" & r).Value
.Fields("FieldNameN") = Range("E" & r).Value

' add more fields
.Update ' stores the new record
End With
r = r + 1 ' next row

Loop


--
Regards,
Tom Ogilvy


"Tom" wrote in message
...
I am using a loop and after walking thru "x" numbers of rows. When I have
walked thru the rows I do the same thing again but I want to move to the
next column and grab the next column of data with the I want to move to

the
next column. How could I accomplish this?

Much thanks in advance!

Tom

Do While Len(Range("A" & r).Formula) 0 And r < 43
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("FieldNameN") = Range("B3").Value
.Fields("FieldNameN") = Range("e17").Text
.Fields("FieldNameN") = Range("A" & r).Value
.Fields("FieldNameN") = Range("B" & r).Value
.Fields("FieldNameN") = Range("C" & r).Value
' After here I would like to change the column to the next column
.Fields("FieldNameN") = Range("D" & r).Value
.Fields("FieldNameN") = Range("E" & r).Value

' add more fields
.Update ' stores the new record
End With
r = r + 1 ' next row

Loop