I have a column on a spreadsheet with a Title of "Action"
In this column, there will either be the word "Add" "Delete" or "Update"
As of the moment, the column goes from G:3 to G:731, but that will grow down.
I need to skip down two from the bottom (I know how to do this) and Count howmany times the word "Add", how many times the word "Delete", how many times the word "Update" appear as well as how many times there is nothing at all listed in this column.
I spent some time Googling =COUNT but I can't find any examples that satisify what I need to do.
you need to provide it with the last cell of the range. I cant remember how to make it figure this out for you when there are blanks in the column off the top of my head, i think i have some code at home though if you really need it ? Let me know !
vb Code:
Sub GetAction()
Dim RANGEBOTTOM As String
Dim cell
Dim strAction As String
Dim intAdd As Integer
Dim intUpdate As Integer
Dim intDelete As Integer
Dim intBlank As Integer
RANGEBOTTOM = "G731"
For Each cell In Range("G3:" & RANGEBOTTOM)
strAction = cell.Value
If UCase(strAction) = "ADD" Then
intAdd = intAdd + 1
ElseIf UCase(strAction) = "UPDATE" Then
intUpdate = intUpdate + 1
ElseIf UCase(strAction) = "DELETE" Then
intDelete = intDelete + 1
ElseIf strAction = "" Then
intBlank = intBlank + 1
End If
Next
MsgBox "Additions =" & CStr(intAdd)
MsgBox "Updates =" & CStr(intUpdate)
MsgBox "Deletions =" & CStr(intDelete)
MsgBox "blanks =" & CStr(intBlank)
End Sub
Last edited by NeedSomeAnswers; Sep 17th, 2008 at 10:38 AM.
Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you
I have made a minor amendment which you might find useful, in this version it should count down to the bottom of your range for you ignoring blanks until it can find no more data, so in effect getting the bottom of your range for you.
edit - messed up the formatting in this post so posted it again below !!
Last edited by NeedSomeAnswers; Sep 17th, 2008 at 11:07 AM.
Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you
Dim ActionRange As Range, r1 As Long, r2 As Long
With Sheet1 '-- your data sheet
r1 = 3
r2 = .Cells(.Rows.Count, "G").End(xlUp).Row
If r2 < r1 Then r2 = r1
Set ActionRange = .Range("G" & r1 & ":G" & r2)
End With
Haven't come across this before, and will be using that now in the future
Cheers !!
Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you
Dim ActionRange As Range, r1 As Long, r2 As Long
With Sheet1 '-- your data sheet
r1 = 3
r2 = .Cells(.Rows.Count, "G").End(xlUp).Row
If r2 < r1 Then r2 = r1
Set ActionRange = .Range("G" & r1 & ":G" & r2)
End With
Haven't come across this before, and will be using that now in the future
Cheers !!
By using Sheet.Rows.Count, it will work for both Excel-2007 and prior. You don't need to know how many rows a worksheet has.
Using BottomCell.End(xlUp) is better than using TopCell.End(xlDown), particularly when there are some blank cells in the middle.
Don't forget to use [CODE]your code here[/CODE] when posting code
If your question was answered please use Thread Tools to mark your thread [RESOLVED]
previously I have tried the xlDown method, but obviously as you said it's no good if you have blank cells, I hadn't thought about counting from the bottom upwards !!
My way was just an ugly work around.
Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you