Calculate variance from combined rows with nested loop for all columns (VBA)

anatomyst

New Member
Joined
Nov 7, 2022
Messages
3
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have started to use VBA and I have the following problem. I want to calculate the variance of the 6th and 9th row. Then, 6th and 12th row (yellow).

The loop should then calculate the 7th and 10th and 7th and 13th row (beige) Finally, the loop should then calculate the 8th and 11th row, 8th and 14th row (orange). Then the first block ends.

The next block should be calculated according to the same principle (red). The Variance should be calculated for columns from a-o. In the end I'll receive the results.

I do not know how to go through it column by column and combined row by row. I would be very grateful for any advice.
 

Attachments

  • Unbenannt.PNG
    Unbenannt.PNG
    81.8 KB · Views: 4

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).
VBA Code:
Sub test3()
Dim sh As Worksheet, rng As Range, lRow As Long, LCol As Long
Dim r As Integer, c As Integer

Set sh = Sheets("Tabelle6")

LCol = sh.Cells(8, Columns.Count).End(xlToLeft).Column
lRow = sh.Cells(rows.Count, "A").End(xlUp).row

Set rng = sh.Range(sh.Cells(lRow + 2, "A"), sh.Cells(lRow + 2, LCol))

For r = 6 To lRow Step 9
With rng
'.Formula = "=VAR.P(A6:A" & lRow & ")"
.Formula = "=VAR.P((IF(MOD(ROW(A6:A" & lRow & ")-ROW(A6)+0,3)=0,A6:A" & lRow & "))"

  .value = .value
End With
Next

With rng.Borders(xlEdgeTop)
  .LineStyle = xlContinuous
  .Weight = xlThick
End With


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,619
Members
449,039
Latest member
Mbone Mathonsi

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