Solved

Command button code

Posted on 2011-03-09
5
282 Views
Last Modified: 2012-05-11
Please can you help, I am hoping to do away with the formulas held within E9:E917 from Sheet3 "Location.

I was hoping to use a command button that could calculate the occurrence of the listed codes (C9:C917) on sheet1 H14:H873

It would then display these in descending order.

The difficulty is that the formulas currently filter the data by the listed dates in F2:F3 sheet3 and matches this to the dates listed in B14:B873 sheet1.





help.xls
0
Comment
Question by:Gazza83
  • 3
  • 2
5 Comments
 
LVL 39

Expert Comment

by:nutsch
ID: 35087367
Here, this code will put in the formula, then copy /paste values it so the formula disappears when you're not updating:

Sub Macro2()
'
With Sheets("Location").Range("E9:E917")
    .FormulaR1C1 = _
        "=SUMPRODUCT((data!R14C2:R20000C2+0>=R2C6)*(data!R14C2:R20000C2+0<=R3C6)*(data!R14C8:R20000C8=RC3))"
    .Value = .Value
End With
End Sub

Open in new window


Thomas
0
 

Author Comment

by:Gazza83
ID: 35087883
Thanks Thomas, this seems perfect! I've run the code and it took little to no processing time; whereas the old way was taken ages.

Is there a way I could sort the range highest-Lowest, maybe I could use another command button?
0
 
LVL 39

Accepted Solution

by:
nutsch earned 500 total points
ID: 35088387
Something like this?

Sub Macro2()

With Sheets("Location").Range("E9:E917")
    .FormulaR1C1 = _
        "=SUMPRODUCT((data!R14C2:R20000C2+0>=R2C6)*(data!R14C2:R20000C2+0<=R3C6)*(data!R14C8:R20000C8=RC3))"
    .Value = .Value
End With

With Sheets("Location").Range("C9:E917")
    .Sort Key1:=Range("E9"), Order1:=xlDescending
End With

End Sub

Open in new window


Thomas
0
 

Author Closing Comment

by:Gazza83
ID: 35088944
Thanks Thomas!
0
 
LVL 39

Expert Comment

by:nutsch
ID: 35088966
Glad to help. Thanks for the grade.

Thomas
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS excel check if Links exist 5 35
Left trim cells in column A Excel vba 2 29
And OR formula 5 22
Select/Copy row and pasting it lower in sheet 7 19
A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
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…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
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…

776 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