Newbie. Please help me find a loop solution

N

Nigel Brown

I am trying to calculate a value for a cell and at the same time store
the previous cell value for the next calculation. The following code
works, but
I need to find a way to loop this until column AN and row 3000. I know
there must be a better solution than how my code works and would be
very greatful if someone can point me in the right direction.

Sub test()
Dim temp As Single
Dim temp2 As Single

temp = Range("m2").Value
Range("m2").Value = Range("j2").Value - temp
temp2 = Range("n2").Value
Range("n2").Value = temp - temp2
temp = Range("o2").Value
Range("o2").Value = temp2 - temp
temp2 = Range("p2").Value
Range("p2").Value = temp2 - temp

End Sub

I know there must be a better solution than how my code works and
would be very greatful if someone can point me in the right direction.

Nigel Brown
 

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