1
votes

I'm working an excel report. I've gotten some help on this site with editing my code but I'm stuck in one place and have no idea how to proceed. So I have code here:

Dim xlStartCol As Long
xlStartCol = xlCol
Do While Not g_RS3.EOF
With xlSheet.Cells(xlRow, xlCol)
    .Resize(1, 2).Merge
    .Value = "TEST" 'g_RS3("ShortLabel")
    .Offset(1, 0).Resize(1, 2) = Array("Clients", "Students")
    .Offset(2, 0).Resize(1, 2).ClearContents
    With .Offset(0, 1)
        .Resize(1, 2).Merge
        .Value = "Total"   'keep writing Total to the right; it will be overwritten if there is another ShortLabel
        .Offset(1, 0).Resize(1, 2) = Array("Clients", "Students")
        .Offset(2, 0).Resize(1, 2).Formula = _
            "=SUMIFS(" & Range(.Parent.Cells(xlRow + 2, xlStartCol), .Parent.Cells(xlRow + 2, xlCol + 1)).Address(0, 1) & Chr(44) & _
                         Range(.Parent.Cells(xlRow + 1, xlStartCol), .Parent.Cells(xlRow + 1, xlCol + 1)).Address(1, 1) & Chr(44) & _
                         .Parent.Cells(xlRow + 1, xlCol - 1).Address(1, 0) & Chr(41)
    End With
    With .Resize(2, 4)
        .Font.Bold = True
        .VerticalAlignment = xlCenter
        .HorizontalAlignment = xlCenter
        .Borders.Weight = xlThin
    End With
End With
xlCol = xlCol + 2
g_RS3.MoveNext
Loop

This makes my report looks like this. What I'm trying to do is use fillDown property to autofill range [the formula is in 2 place under TOTAL, one under clients and one under students. sumifs: clients goes from cell to cell and grabs the number of clients for each TEST heading, same with Students](this row - where the formula is) : and + 6 rows down. Basically I want to have the formula in all 7 rows. Please help me out. Seem image below of what this code does.

enter image description here

2
So you are using @Jeeped answer from your last question but not marking his answer as correct?Scott Craner
I just marked it as completed. I'm new to this site and not exactly sure how everythign works. ThanksFatBoySlim7
Have you recorded yourself doing this?Wyatt Shipman
No I actually got some help on this site.FatBoySlim7
How about just sticking (something like) this statement after you make your formula .Offset(2, 0).Resize(1, 2).AutoFill .offset(2,0).Resize(7,2)Scott Holtzman

2 Answers

1
votes

How about just sticking this statement after you make your formula

.Offset(2, 0).Resize(1, 2).AutoFill .offset(2,0).Resize(7,2)
1
votes

You could also do this

Range("J4:J10").Formula = "=yourformulahere"