Results 1 to 8 of 8

Searching each cell for any combination of 3 characters

Threaded View

  1. #1
    Registered User
    Join Date
    09-07-2010
    Location
    usa
    MS-Off Ver
    Excel 2003
    Posts
    4

    Searching each cell for any combination of 3 characters

    Hi there,

    I'm currently working on a macro that tallies each "A", "G", and "S" that occurs in a column. So, if a cell's contents was "AG", I would like variables atally and gtally to each get +1 to their value. I would also like atally and gtally to each get +1 if the contents are "GA" as well.

    I initially only had to work with "G" and "S", and used a "B" to indicate *both G & S*, but the introduction of a new value "A" screws things up big time.

    Currently, my relevant portion of the macro is essentially:
    (This macro starts by selecting the first cell value of the column and moves down to the next cell right before it loops)
    Do until Selection.Value= ""
    
    If selection.value= "G" then
          gtally = gtally + 1
    elseif selection.value="S" then
          stally = stally + 1
    elseif selection.value="B" then
        gtally = gtally + 1
        stally = stally + 1
    end if
    
    Selection.Offset(1, 0).Select
    
    Loop


    What I would like it to look like is this:
    Do until Selection.Value= ""
       
    If the cell contains the character "G" then
          gtally = gtally + 1
    elseif the cell contains the character "S" then
          stally = stally + 1
    elseif the cell contains the character "A" then
          atally = atally + 1
    end if
    
    Selection.Offset(1, 0).Select
    
    Loop
    How do I do this?
    Last edited by Leith Ross; 09-07-2010 at 11:58 AM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1