+ Reply to Thread
Results 1 to 10 of 10

Counting instances of an offset value???

  1. #1
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161

    Counting instances of an offset value???

    Hi all,

    I'm trying to count all the instances of the letter "M" if they appear 2 cells above a cell in range that has ColorIndex 3 and display the results in cell AG2 once i have this one right i will be able to adapt it to count for all the other letters in different ranges but right now i cant get this to work or do anything, any sugestions????

    Sub maf()
    Dim rng As Range
    With ThisWorkbook.ActiveSheet
    Range("AG2") = mCount
    Set rng = Range( _
    "B3:AF4,B7:AF8,B11:AF12,B15:AF16,B19:AF20,B23:AF24,B27:AF28,B31:AF32,B35:AF36,B39:AF40,B43:AF44,B47:AF48")
    For Each mycell In rng
    If mycell.Interior.ColorIndex = 3 And mycell.Offset(0, -2).Text = "m" Then
    mCount = 1 + 1

    End If
    Next
    End With

    End Sub

  2. #2
    Registered User
    Join Date
    02-18-2005
    Posts
    26
    iam not sure but try this..

    change "For Each mycell In rng"

    into "For Each mycell In rng.cells"

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Simon,

    If you want to move 2 cells up, your code should be MyCell.Offset(-2, 0). Your code is moving 2 cells to the left.

    Sincerely,
    Lieth Ross

  4. #4
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    thanks for the replies.......my offset is (-2, 0) it was a typo on my part, but it still doesnt work.......any other suggestions????


    Simon

  5. #5
    Forum Contributor
    Join Date
    06-10-2004
    Location
    India
    Posts
    1,066
    change your mcount = 1+1

    to

    mcount = mcount + 1

    Mangesh

  6. #6
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    Thanks Mangesh,

    I tried that, th macro runs but appears to do nothing, it does not display a result in AG2, do i need a function to count things the way i want?
    i.e if the color of the cell is red and the cell 2 cells above has text m then add it to the count.

    Can you help?

    Simon

  7. #7
    Forum Contributor
    Join Date
    06-10-2004
    Location
    India
    Posts
    1,066
    Hi Simon,

    the code you provided worked well with me. Can you provide your complete code again.

    Mangesh

  8. #8
    Forum Contributor
    Join Date
    06-10-2004
    Location
    India
    Posts
    1,066
    Another thing I noticed in your code was that you are not priniting the count at the end of the code.

    Your line:
    Range("AG2") = mCount
    should appear just before end sub


    ' your code here
    Range("AG2") = mCount
    End Sub

    This will put the count in the cell AG2

    Mangesh

  9. #9
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    Cheers Mangesh!.........worked a treat!

    Thanks,

    Simon

  10. #10
    Forum Contributor
    Join Date
    06-10-2004
    Location
    India
    Posts
    1,066

    Thanks for your feedback.

    Mangesh

+ Reply to Thread

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