0% found this document useful (0 votes)
40 views

Filter by Colors: Sumvisible

The document contains code snippets for three functions: 1. The SumVisible function sums the values of visible cells in a range, skipping hidden rows and columns. 2. The getColor function returns the color format (index or RGB) of a cell's interior color. 3. The FilterDates subroutine filters a range of dates by hiding columns until the start and end dates in cells AL2 and AM2 are found. The sumfilteredcolums function then sums only the visible columns in the filtered range.

Uploaded by

Himawan Wibisono
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Filter by Colors: Sumvisible

The document contains code snippets for three functions: 1. The SumVisible function sums the values of visible cells in a range, skipping hidden rows and columns. 2. The getColor function returns the color format (index or RGB) of a cell's interior color. 3. The FilterDates subroutine filters a range of dates by hiding columns until the start and end dates in cells AL2 and AM2 are found. The sumfilteredcolums function then sums only the visible columns in the filtered range.

Uploaded by

Himawan Wibisono
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

SUMVISIBLE

Function SumVisible(WorkRng As Range) As Double


'Update 20130907
Dim rng As Range
Dim total As Double
For Each rng In WorkRng
If rng.Rows.Hidden = False And rng.Columns.Hidden = False Then
total = total + rng.Value
End If
Next
SumVisible = total
End Function

FILTER BY COLORS

Function getColor(Rng As Range, ByVal ColorFormat As String) As Variant


Dim ColorValue As Variant
ColorValue = Cells(Rng.Row, Rng.Column).Interior.Color
Select Case LCase(ColorFormat)
Case "index"
getColor = Rng.Interior.ColorIndex
Case "rgb"
getColor = (ColorValue Mod 256) & ", " & ((ColorValue \ 256) Mod 256) & ", " & (ColorValue \
65536)
Case Else
getColor = "Only use 'Index' or 'RGB' as second argument!"
End Select
End Function

SUM BY DATES

Public Sub FilterDates()


'variables to handle to start and end dates value
Dim startdates, enddates As String

'set variable to respective values


startdates = Range("AL2").Value
enddates = Range("AM2").Value

'start at first dates in list


Range("A2").Select

'starting with the first dates, hide colums until the start dates is found
Do While ActiveCell.Value <> startdates
Selection.EntireColumn.Hidden = True

ActiveCell.Offset(0, 1).Select
Loop

'move to the last dates in the list


Range("AL2").Select

'Stating with the las dates, hide colums until end dates is found
Do While ActiveCell.Value <> enddates
Selection.EntireColumn.Hidden = True

ActiveCell.Offset(0, -1).Select
Loop

ActiveSheet.Calculate
End Sub

Public Sub Resetdatesfilter()


'Select all cells (entire worksheet)
Cells.Select
'unhide columns
selestion.EntireColumn.Hidden = False

Range("AL3").Select

ActiveSheet.Calculate
End Sub

Public Function sumfilteredcolums(r As Range)


'Allow the function to be recalculated dynamically
Application.Volatile

'variable for cells in a range


Dim c As Range

'loop through all cells in the range


For Each c In r
'If the columns is not hiddened include the value in the SUM
If c.Columns.Hidden <> True Then
sumfilteredcolums = sumfilteredcolums + c.Value
End If
Next c
End Function

You might also like