Adding alternate columns only if they visible


New Member
Jul 22, 2015

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

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?


Forum statistics

Latest member
Joaquin Phoenix

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...