I'm trying to create a Macro to select and group a certain amount of cells with implementation of some formulas, a simple example picture is included below. The only thing that should determine the range is column A.
Let's say the active cell is somewhere between row 2 and row 9, the Macro should be able to find out that row 1 and row 10 are the boundaries of that range because of the presence of values in column A and so creating and selecting a range going from row 2 till row 9. I tried to loop through the cells going down to find the first row with an active value in column A. After determining the range/group, a formula, calculating the product of those rows, and to finish it of, calculatie a sum of those products in the title row of that group (being the upper row with an active value in column A).
I've included my code so far below, after a bit of trial and error and googling/searching for similar problems on this forum, but my code still doesn't seem to work like I want it to. My not that great knowledge of VBA/scripting doesn't really help :)
A picture is included below with the wanted generated formulas colored in blue.
Dim StartCell, EindCell As Range
Dim teller As Integer
Dim teller2 As Integer
Cells(Application.ActiveCell.Row, 1).Select
teller = 0
Do While Selection.Offset(teller, 0).Value = ""
teller = teller - 1
Loop
Selection.Offset(teller, 0).Select
Set StartCell = ActiveCell
teller2 = 0
Do While Selection.Offset(teller, 0).Value = ""
teller = teller + 1
Loop
Selection.Offset(teller, 0).Select
Set EindCell = ActiveCell
Range(StartCell, EindCell).Select
Selection.Rows.Group
Cells(Application.ActiveCell.Row, 8).Select
ActiveCell.Formula = "=PRODUCT(RC[-4]:RC[-1])"
Selection.NumberFormat = "0.00"
Range(StartCell.Row + 1, 9).Formula = "=sum(cells(StartCell.row,8):Cells(EindCell.row,8))"
Please try this code.
This works for however many groups you have in one sheet. If the user selects a cell past the last used row then it'll assume they meant the last group
I believe the code below will do what you expect: