PDA

View Full Version : Solved: How to Recognize this string properly?



Saladsamurai
08-24-2009, 07:11 PM
Hello there:hi:

I am trying to use an If-then to check and see if the first column of each row reads as follows: T (°F) CFD
If it does, then I increment j. Where am I going wrong?

Thanks!!:hi:




EDITED: typo
Sub WriteEquipmentType()
Dim i, j As Integer
j = 0
For i = 1 To 860
If Worksheets("Raw Data").Cells(i, 1) = "T (" & Chr(176) & "F CFD)" Then j = j + 1
Next i
MsgBox j




End Sub

geekgirlau
08-24-2009, 08:34 PM
Sub WriteEquipmentType()
Dim i, j As Integer
j = 0
For i = 1 To 860
If Worksheets("Raw Data").Cells(i, 1) = "T (" & Chr(176) & "F) ISX" Then j = j + 1
Next i
MsgBox j
End Sub

Saladsamurai
08-25-2009, 04:33 AM
Sub WriteEquipmentType()




Dim i, j As Integer
j = 0
For i = 1 To 860
If Worksheets("Raw Data").Cells(i, 1) = "T (" & Chr(176) & "F) ISX" Then j = j + 1
Next i
MsgBox j
End Sub







Sorry. It was supposed tp read CFD (I just copy/pasted too quickly). Edited to correct.

Thanks! I didn'teven see that my right-parenthesis was located incorrectly! :banghead:

mdmackillop
08-25-2009, 05:54 AM
To avoid looping

Sub WriteEquipmentType()
Dim j As Long, k As Long
Dim rng As Range

Set rng = Worksheets("Raw Data").Cells(1, 1).Resize(860)

j = Application.WorksheetFunction.CountIf(rng, "T (" & Chr(176) & "F CFD)")
'or
k = Application.WorksheetFunction.CountIf(rng, "T (°F CFD)")

MsgBox j
MsgBox k

End Sub