Autosum at an empty cell in column. Only autosum for visible cells!

Madter

New Member
Joined
Oct 16, 2017
Messages
24
Hi guys.
I have a data sheet which is attached here.
I get a new data sheet like this every day, and that is why i need it to autosum where the red arrows are pointing in the attached picture.
I've used filter so i only need it for the visible cells.

I have this macro;
Code:
Sub AutoSum()
Dim Area As Range, MyColumn As String
MyColumn = "A"
    For Each Area In Columns(MyColumn).SpecialCells(xlConstants, xlNumbers).Areas
        SumAddr = Area.Address(False, False)
        Area.Offset(Area.Count, 0).Resize(1, 1).Formula = "=SUM(" & SumAddr & ")"
    Next Area
End Sub
..where i've tried substituting "xlConstants" with xlCellTypeVisible and deleting xlNumbers, but i can't seem to get it to work.
Any suggestions?

https://www.screencast.com/t/jwSSZNW1Us
Thanks
 
Last edited by a moderator:
If you want the code to work on column H, your code should surely read:

Code:
MyColumn = "H"

and not:

Code:
MyColumn = "A"
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
If you want the code to work on column H, your code should surely read:

Code:
MyColumn = "H"

and not:

Code:
MyColumn = "A"

I Know, that's not the issue. The issue is that the autosum sums all Numbers from the empty Cell and upwards instead of taking the visible cells only
 
Upvote 0
Try:
Code:
Sub AutoSum()

    Dim x       As Long
    Dim LR      As Long
    Dim start   As Long
    
    Application.ScreenUpdating = False
    
    With ActiveSheet
        If .AutoFilterMode Then .AutoFilter = False
        LR = .Cells(.Rows.count, 1).End(xlUp).row
        start = 2
        For x = 2 To LR
            If Len(.Cells(x + 1, 1)) = 0 And start < x Then
                adj = 1
                If Abs(x - start) = 1 Then adj = 0
                .Cells(x + adj, 8).Value = Application.SumIf(.Cells(start, 1).Resize(x), "N", .Cells(start, 8).Resize(x - start + 1))
                start = x + 2 + adj
            End If
        Next x
    End With
    
    Application.ScreenUpdating = True
    
End Sub
 
Last edited:
Upvote 0
You should use SUBTOTAL rather than SUM then:

Code:
.Formula = "=SUBTOTAL(109," & SumAddr & ")"
 
Upvote 0
Try:
Code:
Sub AutoSum()

    Dim x       As Long
    Dim LR      As Long
    Dim start   As Long
    
    Application.ScreenUpdating = False
    
    With ActiveSheet
        If .AutoFilterMode Then .AutoFilter = False
        LR = .Cells(.Rows.count, 1).End(xlUp).row
        start = 2
        For x = 2 To LR
            If Len(.Cells(x + 1, 1)) = 0 And start < x Then
                adj = 1
                If Abs(x - start) = 1 Then adj = 0
                .Cells(x + adj, 8).Value = Application.SumIf(.Cells(start, 1).Resize(x), "N", .Cells(start, 8).Resize(x - start + 1))
                start = x + 2 + adj
            End If
        Next x
    End With
    
    Application.ScreenUpdating = True
    
End Sub

It gives me a run-time error "'438': Object doesn't suport this property or method" on the .Autofilter=False.
What to do?
 
Upvote 0
Change to .Autofiltermode = False

No need to re-quote the entire previous reply back, it's still visible on the thread and readable. Quoting the entire reply just makes this thread longer and more to scroll through. Unless you have a different perspective?
 
Upvote 0
No, you're right :)

And we are almost there! But now it just deletes the filters, and almost leaves the sheet as it was before the filters, with the exception of the sum of the column we wanted. :/
 
Upvote 0
Try:
Code:
Sub AutoSum()


    Dim x       As Long
    Dim LR      As Long
    Dim start   As Long
    
    Application.ScreenUpdating = False
    
    With ActiveSheet
        If .AutoFilterMode Then .AutoFilterMode = False
        LR = .Cells(.Rows.count, 1).End(xlUp).row
        start = 2
        For x = 2 To LR
            If Len(.Cells(x + 1, 1)) = 0 And start < x Then
                adj = 1
                If Abs(x - start) = 1 Then adj = 0
                .Cells(x + adj, 8).Value = Application.SumIf(.Cells(start, 1).Resize(x), "N", .Cells(start, 8).Resize(x - start + 1))
                start = x + 2 + adj
            End If
        Next x
        With .Cells(1, 1).Resize(LR, 10)
            .AutoFilter
            .AutoFilter Field:=8, Criteria1:="<>"
            .AutoFilter Field:=1, Criteria1:="N"
        End With
    End With
    
    Application.ScreenUpdating = True
    
End Su
 
Last edited:
Upvote 0
But it doesn't have to be connected with the filters in column "A". The only thing that is important, is that after filtering the sheet, i need the sum at the empy cells of column H
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,157
Members
453,021
Latest member
Justyna P

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