looping every third row

J

Jason Hancock

I am trying to write a loop that will iterate every third row from row 4
to row 238. Each iteration would be as follows.

Range("C4").Select
ActiveCell.FormulaR1C1 = "=R[-1]C[0]-R[-2]C[0]"
Selection.NumberFormat = "$#,##0_);[Red]($#,##0)"
Range("C4:C4").AutoFill Destination:=Range("D4:O4")

I know I could write this in C++ with a for loop, but I'm not sure how I
would write this in VB. Any help would be great!

Jason


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
P

Paul Lautman

Untested:
for n = 4 to 238 step 3
cell(n,3).FormulaR1C1 = "=R[-1]C[0]-R[-2]C[0]"
cell(n,3).NumberFormat = "$#,##0_);[Red]($#,##0)"
Not sure what you're attempting with the next line???
Range("C4:C4").AutoFill Destination:=Range("D4:O4")
next
 
J

Jason Hancock

I am getting compile error: sub or function not defined on the
cell(n,3). Do I need to Dim the cell?



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
J

Jason Hancock

Yeah, that got it. Cells instead of cell. I should have known that
from my errors with sheet and sheets.

As for the line that had an unknown meaning:

Range("C4:C4").AutoFill Destination:=Range("D4:O4")

I'm trying to get the formula to be put in columns C through O. This
line, in a modified state, succeeded in putting dates in several cells,
however now I am getting a Runtime Error '1004'. Any ideas?




*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 

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