Solved

Excel Automation

Posted on 2011-09-28
7
161 Views
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
                Else
                End If
            Else
            End If
        End With
    Next c
End Sub


Cheers

Carlton
0
Comment
Question by:cpatte7372
  • 4
  • 2
7 Comments
 
LVL 24

Expert Comment

by:StephenJR
Comment Utility
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?
0
 
LVL 37

Accepted Solution

by:
Neil Russell earned 250 total points
Comment Utility
You could just add

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

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

Author Comment

by:cpatte7372
Comment Utility
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.

Cheers
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:cpatte7372
Comment Utility
Stephen, the cells tha would activate it would be cells AW5:AW17

Cheers
0
 
LVL 24

Assisted Solution

by:StephenJR
StephenJR earned 250 total points
Comment Utility
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

0
 

Author Comment

by:cpatte7372
Comment Utility
Neil/Stephen,

Cheers guys
0
 

Author Closing Comment

by:cpatte7372
Comment Utility
Cheers guys
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now