Referencing and Formulas

Melpp

New Member
Joined
May 3, 2011
Messages
29
Hi,

I am trying to create a loop that will add automatic referencing. This is a sample formula that I would enter in the regular Excel "='Ant (AUC)'!B4/'Ant (peaks)'!B4" . How can I automate this for a series of rows and columns in Excel Macros?I tried the following code with no luck.

For j = 2 To 16
For i = 1 To 4
b = i + Row_No
area = Worksheets("Ant (AUC)").Range(j & b).Value
peak = Worksheets("Ant (peaks)").Range(j & b).Value
Range(j & b) = area / peak
Next i
Next j
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try:

Code:
Sub Test()
    Const Row_No As Long = 3
    Dim j As Long, i As Long
    Dim B As Long
    Dim area, peak
    For j = 2 To 16
        For i = 1 To 4
            B = i + Row_No
            area = Worksheets("Ant (AUC)").Cells(j, B).Value
            peak = Worksheets("Ant (peaks)").Cells(j, B).Value
            Cells(j, B).Value = area / peak
        Next i
    Next j
End Sub

You hadn't defined Row_No so I used a constant.
 
Upvote 0
That's probably because of divide by zero. Make sure that all the source cells contain a value other than zero. Or use an error trap.
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,183
Members
452,893
Latest member
denay

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