excelnoob1985
New Member
- Joined
- Jul 22, 2015
- Messages
- 6
Hi,
I have data in a sheet which runs from column 'F' to column 'GU' over hundreds of rows. Every column (with headers on row 7) is alternatively named "Hours" and "Fees". Is there a way to have a total figure in columns 'GW' (for Hours) and 'GX' (for Fees) which adds up the respective Hours and Fees figure for each row, and only for visible columns (as the columns from 'F' to 'GU' are needed to be hidden / unhidden repetitively by users as part of using the workbook).
I have used the following code:
Public Function SumVisible(r As Range) As Double
Dim rC As Range
Dim d As Double
Application.Volatile
On Error Resume Next
For Each rC In r
If Not (rC.EntireRow.Hidden Or rC.EntireColumn.Hidden) Then _
If VarType(rC.Value) = vbDouble Then _
d = d + rC.Value
SumVisible = d
Next rC
End Function
Which adds the values in each row for every column but I can't get it work for every alternate row so i have totals for "Hours" and "Fees" separately.
Is there a way to add by reference to the title of the column in row 7, and for the formula to add data in only visible columns?
Thanks!
I have data in a sheet which runs from column 'F' to column 'GU' over hundreds of rows. Every column (with headers on row 7) is alternatively named "Hours" and "Fees". Is there a way to have a total figure in columns 'GW' (for Hours) and 'GX' (for Fees) which adds up the respective Hours and Fees figure for each row, and only for visible columns (as the columns from 'F' to 'GU' are needed to be hidden / unhidden repetitively by users as part of using the workbook).
I have used the following code:
Public Function SumVisible(r As Range) As Double
Dim rC As Range
Dim d As Double
Application.Volatile
On Error Resume Next
For Each rC In r
If Not (rC.EntireRow.Hidden Or rC.EntireColumn.Hidden) Then _
If VarType(rC.Value) = vbDouble Then _
d = d + rC.Value
SumVisible = d
Next rC
End Function
Which adds the values in each row for every column but I can't get it work for every alternate row so i have totals for "Hours" and "Fees" separately.
Is there a way to add by reference to the title of the column in row 7, and for the formula to add data in only visible columns?
Thanks!