Hi I have tried to figure out how to count all cells in a column and subtract any cells that contain characters with a red font. I'll attach an example. I need code that will work in VBA so that in the case that the column does not contain any cells with red numbers it won't come up with a debug error.
In excel I normally do this manually with this formula: =count("") I normally highlight all cells except the red ones.
See attachment for example.
Also, the # of rows is never the same. Some files will be 100 rows, some will be 1000, depending on the store's file we get. so the code would probably have to contain something like .lastactiverow or something. (sorry I'm new to VBA and don't know much)
Thanks in advance!
Curbster
Last edited by curbster; 08-18-2009 at 05:21 PM.
Hi Curbster,
The following code will count all cells in column C that don't have a red font color and then display the non-red count in a message box once finished. You could, of course, have the count entered into a cell on the worksheet instead.
Sub countNonRed() Dim i As Long, cellCount As Long For i = 1 To Range("C65536").End(xlUp).Row If Range("C" & i).Font.ColorIndex <> 3 Then cellCount = cellCount + 1 End If Next i MsgBox cellCount End Sub
Thanks, that gives me the message box as you stated which is great. I guess I don't understand how to get that number to the cell I need...
the number needs to be in column C, the second cell below the last active row. any ideas?
thanks!
Sure, change:
toMsgBox cellCountRange("C" & Range("C65536").End(xlUp).Row + 2).Value = cellCount
That works! thanks!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks