VBA - Determine first and last row in range in order to calculate correlation

Rogue_Trader

New Member
Joined
Oct 2, 2013
Messages
13
Hi guys, I'm currently using Excel 2010 on windows 7.

My issue is I have a sheet filled with data that has random separations (empty rows) for which I need to calculate correlations of the data in between the empty rows. For example I have data filling the range of D6:AA657 but with empty rows inserted randomly into the range.

My fixed column for calculating correlations is D and I want to go from column E all the way till it finds an empty header in Row3 (currently I just use 20 as a proxy in my code). Once I find the begining and end of the current segment of data I calculate correlations of Range D6:D* with Column E, F, G etc till it finds the empty header. It then enters the values along the empty row.

My current draft is below, it currently gives me errors, I was hoping someone could help me out a bit.

Code:
Sub Correl()
Dim rRngA As Range, RowLast As Long


Sheets("Buckets").Activate
Set RowLast = Range("D" & Rows.Count).End(xlUp).Row


Set rRngA = Range("D6", Range("D6").End(xlDown)) 'la colonne fixe
For i = 0 To 20
Set rRngB = rRngA.Offset(, 3 + i) ' allez à D
ans = Application.WorksheetFunction.Correl(rRngA, rRngB)
Cells(RowLast, 7 + i) = ans
Next


End Sub

Any help would be greatly appreciated,

Cheers,

RT
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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