Strings and Cells

bountiful

New Member
Joined
Jun 18, 2015
Messages
31
Help!

I'm trying to simply count up the number of opened and closed tickets to tally them up and I can't seem to get my cells referenced correctly.

P.S. I've only been coding vba for two days so cut me some slack xD i'm sure it's easy.
the sheet is called data and the ticket status is in column 2

Dim ClosedCount As Integer, Tcount As Range
ClosedCount = 0
Set Tcount = Sheets("Data").UsedRange
Set Tcount = Tcount.Columns(2)
For x = 1 To 29563 ' I need a dynamic refference (cClosed.End did not work)
If Cells(x, 2).Val = "Closed" Then
ClosedCount = ClosedCount + 1
Tcount = Tcount + 1
Else
Tcount = Tcount + 1
End If

MsgBox (cClosed.End(xlUp))
Next x
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
What column you want to count? If column B, use:
=COUNTIF($B$1:$B$29563,"Closed")
 
Upvote 0
Modified classic Range.Find example a bit for your needs

Code:
Sub countClosed()
    Dim c As Range
    Dim firstAddress As String
    Dim count As Long
    
    count = 0
    With Sheets("Sheet5").Range("B:B")
        Set c = .Find("Closed", LookIn:=xlValues)
        If Not c Is Nothing Then
            firstAddress = c.Address
            Do
                count = count + 1
                Set c = .FindNext(c)
            Loop While Not c Is Nothing And c.Address <> firstAddress
        End If
    End With
    Debug.Print count
End Sub
 
Upvote 0
this is quite close to being VERY helpful to me, I fon't understand the "If Not C" line and the ".Range("B:B")" Parts

Thanks for your help :)
 
Upvote 0
If Not c is Nothing
checks if a cell was found and returned by Find.

Range("B:B")
means entire column B - all cells in that column.
 
Upvote 0
Probably because you don't have "Sheet5" in your file. Update highlighted with your sheet name

Code:
With Sheets("[COLOR=#ff0000]Sheet5[/COLOR]").Range("B:B")
 
Upvote 0
I switched it to sheet1 and tried using it's name "Data"

"Data" worked, thank you so much for the help. 5 points to V_domo.
 
Upvote 0

Forum statistics

Threads
1,215,366
Messages
6,124,516
Members
449,168
Latest member
CheerfulWalker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top