Hi Everyone,
I am relatively new to
vb and as such have been using the macro recorder to help me take my baby steps along the way. As such my code is exeptionally slow. I have been given the advice that to speed it up use variables instead of cells in the workbook itself. I am trying to get my countif function working using variables, however I have gotten stuck trying to count the total number of rows in the worksheet. I have done this before successfully and have literally copied code across but it's not working. Can anyone provide some help on what's going wrong? I have posted my code below.
Any other feedback or tips on how to get my code running faster would be much appreciated.
Sub Countif_trial()
Dim x As Long, var1 As Long, var2 As String
Sheets("Sheet2").Select
var2 = Range("A2").Value
With ThisWorkbook.Sheets("Sheet1")
x = .Cells(.Rows.count, 1).End(x1Up).Rows.count
var1 = Application.WorksheetFunction.CountIf(Range("A2:A" & x), var2)
End With
MsgBox var1
End Sub
Thanks,
Matt