# Count the number of times the If statement is true

#### Esmannitor

##### New Member
Hi,
I am doing an assignment in IT. I don't have that much experience in VBA, so my code below is pretty primitive. I have some troubles with the If statements. I want to count the number of times the If statement is True and bind it to "CountL". So in my assignment as shown below, I want it to search through column 2 to last column and then if there are any cells with "L" as the first character, then it should count it and add it to the CountL, so I can use it later depending on the value.
What is the best way to do this?

With ws.Range("A:A")
If Not FindAddRow Is Nothing Then
Do
End If
End With

Dim LastColumn As Integer
Dim CountL As Integer
LastColumn = WorksheetFunction.CountA(Range("2:2"))

For Target_Cells = 2 To LastColumn
CountL = Count(Upper statement = True)
End If
Next Target_Cells

### Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

#### Momentman

##### Well-known Member
I modified it slightly but couldn't test it
Code:
``````Sub NewMacro()
With ws.Range("A:A")
If Not FindAddRow Is Nothing Then
Do
End If
End With

Dim LastColumn As Integer
Dim CountL As Integer
LastColumn = WorksheetFunction.CountA(Range("2:2"))

CountL = 0
For Target_Cells = 2 To LastColumn
CountL = CountL + 1
End If
Next Target_Cells
End Sub``````

#### Esmannitor

##### New Member
That was actually a very easy change.
It works like a charm and you are definetly my VBA hero.
Thank you very much!

#### Momentman

##### Well-known Member
That was actually a very easy change.
It works like a charm and you are definetly my VBA hero.
Thank you very much!

Thanks for the feedback. You are welcome

Replies
0
Views
212
Replies
0
Views
2K
Replies
4
Views
257
Replies
1
Views
167
Replies
7
Views
914

1,191,190
Messages
5,985,202
Members
439,947
Latest member
fabiannic

### 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.

### Which adblocker are you using?

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

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