+ Reply to Thread
Results 1 to 4 of 4

ActiveCell Macro

  1. #1
    Registered User
    Join Date
    03-24-2005
    Posts
    20

    Question ActiveCell Macro

    Am looking for help on active cell. Need something to look at the curent cell and count
    based on the value of that cell (If cell.value = 2 then count = 1) this would be done on several worksheets with the same macro. The count for all the sheets would go into one cell something like

    if ActiveCell.Value = 2, 3 or 4 Then Count
    Range("AQ38").Value = Count

    Any help would be wonderful!

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good morning Information Hog

    This piece of code will do exactly what you wanted:

    Sub example()
    a = 0
    b = ActiveCell.Address
    For Each sht In ActiveWorkbook.Worksheets
    sht.Activate
    Range(b).Select
    If ActiveCell = "2" Or ActiveCell = "3" Or _
    ActiveCell = "4" Then a = a + 1
    Next sht
    MsgBox a
    End Sub

    The number of times this number occurs is held in the variable a.
    Your post didn't state so I made the assumption that you wanted the same cell checked in every sheet. If you want the active cell in each sheet checked, omit the Range(b).Select line.

    To put the result in a cell use these lines in place of Msgbox a

    Sheets("Sheet1").Select
    Range("F10").Select
    ActiveCell.FormulaR1C1 = a

    HTH

    DominicB

  3. #3
    Registered User
    Join Date
    03-24-2005
    Posts
    20

    Thumbs up

    Thank's so much for your help with the code, that was perfect!

  4. #4
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Hi Information Hog

    You're welcome. Glad you found it of use, and thank you for the feedback.

    DominicB

+ 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