For Excel 2010 under Windows 7
I'd like to write a function that sums a range based on the formatting of the cell. I wrote this, which worked wonderfuly:
The function then returns the runningTotal variable. Then I tried to expand on this. I wanted to pass a code number to the function, and have it change the formatting criteria based on that code (similar to the SUBTOTAL function). Using a Select Block to parse the code number was simple, I didn't want to copy the same For Each loop into each case though. My thought was to pass a string with code to return the proper format criteria to the If block and then using something similar to BASH's eval statement to expand the string. However, looking over the help page on the Application.Evaluate method, it seems that will only expand Excel defined names. Is there a way to have VBA expand a string as a statement? Something like:
Or perhaps this isn't the most efficient solution. Is there another way to store a set of properties in a variable and then pass them to an object? Thanks.
Jim
I'd like to write a function that sums a range based on the formatting of the cell. I wrote this, which worked wonderfuly:
Code:
For Each cell In target
If cell.Font.Italic = True Then
runningTotal = runningTotal + cell.Value
End If
Next
Code:
Dim searchTerm As String
searchTerm = "cell.Font.Italic"
For Each cell In target
If {searchTerm} = True Then
runningTotal = runningTotal + cell.Value
End If
Next
Jim