Looping

  • Thread starter Thread starter Todd Huttenstine
  • Start date Start date
T

Todd Huttenstine

Hey guys,

The below 3 lines of code do the same thing, however I
will need to go all the way down from row 3 to row 100 and
do not want to write another 97 lines of code. What would
the loop code be to accomplish what the below code does
for row3 to row100?

Worksheets(8).Range("H3").Value = Worksheets(8).Range
("P3").Value * Worksheets(8).Range("Q3").Value
Worksheets(8).Range("H4").Value = Worksheets(8).Range
("P4").Value * Worksheets(8).Range("Q4").Value
Worksheets(8).Range("H5").Value = Worksheets(8).Range
("P5").Value * Worksheets(8).Range("Q5").Value

Thank you
Todd Huttenstine
 
If you are always performing this calc on rows 3 - 100, you can use:

For x = 3 to 100
Worksheets(8).Range("H"&x).Value = Worksheets(8).Range("P"&x).Value * _
Worksheets(8).Range("Q"&x).Value
Next x

If you always begin at row 3 but the length changes, try:

x = 3
While Range("P"&x)<>""
Worksheets(8).Range("H"&x).Value = Worksheets(8).Range("P"&x).Value * _
Worksheets(8).Range("Q"&x).Value
x=x+1
Wend

HTH
 
you could try the range assignment technique

[a1:a100] = [b1:b100]

this will copy the range in column B to column A. this is
a lot faster than looping.
 
Hi

Try this

Sub test()
With Worksheets(8)
For rw = 3 To 100
..Range("H" & rw).Value = .Range("P" & rw).Value * .Range("Q" & rw).Value
Next
End With
End Sub
 
Back
Top