Consulting

Results 1 to 4 of 4

Thread: Dcount Last Character In Column

  1. #1
    VBAX Regular
    Joined
    Jun 2008
    Posts
    72
    Location

    Dcount Last Character In Column

    Is it possible to do a DCount on a the last character in a column?

    Example: Suppose column A has the following data...
    RGR
    RARG
    AGGR
    GRAGA

    I'd like to count the number of rows where the last character = R (The answer would be 2 in this example).

  2. #2
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    266
    Location
    Sub Find_R()
    Dim mycell
    For Each mycell In Range("G1", "G500") '<-- change to suit
        If Right(mycell.Value, 1) = "R" Then
            answer = answer + 1
       End If
    Next mycell
    MsgBox answer
    End Sub

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    PHP Code:
    =SUMPRODUCT(--(RIGHT(A1:A4,1)="R")) 
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Even better

    PHP Code:
    =COUNTIF(A1:A4,"*R"
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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