Excel Automation

Posted on 2011-09-28
Last Modified: 2012-05-12
Hello Experts,

A clever expert assisted me with the following formula. However, he appear busy and I was wondering if someone could show me how to make it run dynamically without having to hit F5 or click run?

Sub compile_duplicates()
    colStart = "AW"
    rowStart = 5
    cellStart = colStart & rowStart
    For Each c In Range(cellStart & ":" & colStart & (Cells.SpecialCells(xlCellTypeLastCell).Row)).Cells
        With WorksheetFunction
            colnum = .CountIf(Range(cellStart & ":" & colStart & (Cells.SpecialCells(xlCellTypeLastCell).Row)), c)
            If colnum > 0 Then
                yaxis = .Substitute(Left(Cells(1, colnum + Range(colStart & 1).Column).Address, .Find("$", Cells(1, colnum + 1).Address, 2)), "$", "")
                If .CountIf(Range(yaxis & ":" & yaxis), c) < 1 Then
                    xaxis = .CountA(Range(yaxis & rowStart & ":" & yaxis & Cells.SpecialCells(xlCellTypeLastCell).Row)) + rowStart
                    Range(yaxis & xaxis) = c
                End If
            End If
        End With
    Next c
End Sub


Question by:cpatte7372
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 24

Expert Comment

ID: 36716790
Carlton - you could make it run every time a cell is changed, or selected, or double-clicked or right-clicked etc. What would you like? If the former, which cell(s) should activate it?
LVL 37

Accepted Solution

Neil Russell earned 250 total points
ID: 36716829
You could just add

Private Sub Worksheet_Change(ByVal Target As Range)
        Application.EnableEvents = False
        Application.EnableEvents = True
End Sub

Into the worksheet  code module IF you wanted it fire on EVERY change to that worksheet

Author Comment

ID: 36718053
Hello guys,

Sorry for the long delay in responding.

Neil, I'm not sure if it would be a good idea to have formula fired on EVERY change as the spreadsheet is literally changing every second.

Therefore, Stephen, it would be great if you could assist in having the spreadsheet just fire when cell chnages in column AW.

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.


Author Comment

ID: 36718061
Stephen, the cells tha would activate it would be cells AW5:AW17

LVL 24

Assisted Solution

StephenJR earned 250 total points
ID: 36718096
Just add this line in Neilsr's code before the false line.
If Intersect(Target, Range("AW5:AW17")) Is Nothing Then Exit Sub

Open in new window


Author Comment

ID: 36720399

Cheers guys

Author Closing Comment

ID: 36720402
Cheers guys

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question