Consulting

Results 1 to 4 of 4

Thread: Solved: How to Recognize this string properly?

  1. #1

    Solved: How to Recognize this string properly?

    Hello there

    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!!




    EDITED: typo
    [vba]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
    [/vba]
    Last edited by Saladsamurai; 08-25-2009 at 04:32 AM.

  2. #2
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    [VBA]
    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
    [/VBA]

  3. #3
    Quote Originally Posted by geekgirlau
    [vba]
    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
    [/vba]



    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!

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    To avoid looping
    [vba]
    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

    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •