Sumvisible VBA to keep re-calculating

kjsmercier

New Member
Joined
Dec 15, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
HI all: I have a sheet where the columns are visible based on a cell count (that is manually typed in see cell CT1 and 2). I would like the total row (DO5) to update off of visible columns but also recalculate every time I change the number. I am using this VBA Thank you!:
Function SUMVisible(Rg As Range)
Dim xCell As Range
Dim xCount As Integer
Dim xTtl As Double

Application.Volatile
Set Rg = Intersect(Rg.Parent.UsedRange, Rg)

For Each xCell In Rg
If xCell.ColumnWidth > 0 _
And xCell.RowHeight > 0 _
And Not IsEmpty(xCell) _
And IsNumeric(xCell.Value) Then
xTtl = xTtl + xCell.Value
xCount = xCount + 1
End If
Next
If xCount > 0 Then
SUMVisible = xTtl
Else
SUMVisible = 0
End If
End Function
 

Attachments

  • Screenshot 2023-01-06 170512.png
    Screenshot 2023-01-06 170512.png
    24.1 KB · Views: 8

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Sub SUMVisible()
Dim lngRow As Long, lngCol As Long
Dim rngRange As Range

Set rngRange = Range("A1:D20") 'Set your range here

For lngRow = 1 To rngRange.Rows.Count
For lngCol = 1 To rngRange.Columns.Count
If rngRange.Columns(lngCol).EntireColumn.Hidden = FALSE Then
Cells(lngRow, 5).Value = Cells(lngRow, 5).Value + Cells(lngRow, lngCol).Value
End If
Next
Next
End Sub
 
Upvote 0
Sub SUMVisible()
Dim lngRow As Long, lngCol As Long
Dim rngRange As Range

Set rngRange = Range("A1:D20") 'Set your range here

For lngRow = 1 To rngRange.Rows.Count
For lngCol = 1 To rngRange.Columns.Count
If rngRange.Columns(lngCol).EntireColumn.Hidden = FALSE Then
Cells(lngRow, 5).Value = Cells(lngRow, 5).Value + Cells(lngRow, lngCol).Value
End If
Next
Next
End Sub
Is this in replacement or in addition to?
 
Upvote 0

Forum statistics

Threads
1,215,130
Messages
6,123,220
Members
449,091
Latest member
jeremy_bp001

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