Using Offset in a For Each loop

Yeoman.jeremy

Board Regular
Joined
Apr 4, 2011
Messages
90
Hi,
I currently have this:
Code:
Private Sub CalcPUnit_Click()Dim rCell As Range
Dim rRng As Range


Worksheets("Inventory").Select
Set rRng = Range("E3:E50")


For Each rCell In rRng
rCell.Value = rCell.Offset(, 2) / rCell.Offset(, 1)
Next rCell
  
End Sub

Basically to say each cell in a range needs to become the value of 2 cells to the left divided by 1 cell to the left.
Whenever I run this code I get an overflow error.
Any ideas?

Thanks
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi,

If your amounts are " to the left " ...

You need to adjust your Offsets : Offset(,-2) and Offset(,-1)

HTH
 
Upvote 0
Hi, not correct :)
Also the problem wasn't with the directions it was something else :) thanks though

Feel free ... not to stay mysterious ... about THE solution you have found ...
 
Upvote 0
Try:
Code:
For Each rCell In rRng
If IsNumeric(rCell.Offset(, 2).Value) And rCell.Offset(, 1).Value <> 0 Then
rCell.Value = rCell.Offset(, 2) / rCell.Offset(, 1)
End If
Next rCell
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,472
Members
449,087
Latest member
RExcelSearch

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top