Question

Can anyone run this super crazy macro for me on their supercomputer or something?

Asked by: piyushdabomb

Hey,

I developed an excel macro that traverses through 11 different pairing combinations (a total of approximately 135 million combinations). Given this said, its taking like 3 days to run and its been running since Monday ...(and as I type this message, its still running).

Given this said, does anyone have a supercomputer or give me advise as to how I can significantly speed up the process of this automation?

To give you an overview, here is the way this press-of-a-button works:

Essentially, lets say I have letters A, B, C, and D and for each letter I have the following (note that this can change any time to as many sub-lettered values):

A1, A2, A3, A4
B1, B2, B3, B4, B5, B6
C1, C2
D1, D2, D3, ...

What the automation does is first calculates the high level letter pairs and then the lower level pairs:
A, B, C, D to give me:

Pairs of 2:
AB, AC, AD
Now for AB, the combinations are A1,B1; A1,B2...all the way to A4,B6

Similarly, pairs of 3:
ABC, ABD, ACD
Therefore for ABC: A1,B1,C1, A1,B1,C2...all the way to A4,B6,C2

Simple enough right? Okay great...so now, low level pair, there is a comparison made and the highest value found in the "PerceivedValue" sheet for that comparison is saved.

Anyway....this is a simpliefied version. The worksheets involved are "Combinations" and "Perceived Value".

Once the whole thing runs, all the values are spit out on the "Chart" sheet. Even though there are 135 million or so combinations, only at most 65K items should be displayed on the "Chart" sheet.

-------------------------------------

Either one PLEASE try to simplify this code to give me quicker/faster results or run this on their super fast machine.

All you need to do is click "Generate Combinations" in the "Combination" worksheet.

Enclosed!

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-01-29 at 08:35:00ID24095187
Tags

Microsoft Excel 2003 (Visual Basic for Applications)

Topics

Microsoft Excel Spreadsheet Software

,

VB Script

,

Spreadsheet Software

,

Microsoft Office Suite

Participating Experts
2
Points
500
Comments
10

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. For every worksheet in the workbook, select cell a1
    I have a workbook with multiple worksheets and chart sheets. I have a clean up routine that does some formatting. I'd like to end it with each worksheets a1 cell selected.
  2. cell a1
    I had put command botton and 1 text box in excell worksheet. and in command botton code is "Sheet1.Columns(a1, a1) = TextBox1.Text 'Sheet1!b2 = TextBox2.Text" why it fail ? i just one when the time i write word "Hujan" in the text box 1 , that word will ...
  3. Open worksheet in cell A1
    Hi! This should be easy for u!! How do I get Excel to always open a worksheet in cell A1 when I click on the worksheet tab? Regards, EricM
  4. Combining worksheets and workbooks
    I have a workbook with a number of worksheets. I want to combine the existing sheets on a new sheet such that the sheets are one above the other and starting from column B. Column A should be filled with the name of the original worksheet against the data for that worksheet. ...
  5. macro to copy part of worksheet to all other worksheets in …
    Hi Experts I need a macro to copy the data from cells "A1 through to J9 in the active worksheet, to the same location all other worksheets within the workbook then also the contents of active worksheet, cells "H11,H12,H13" to the same location in all other wor...
  6. Jumping to cell A1 of another worksheet.
    I just did saving the workbook, Id like to jump to worksheet 'B' cell A1. How to code that in VBA....

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: GrahamSkanPosted on 2009-01-31 at 02:00:52ID: 23516113

You have a routine to called CopyArray which you use to expand an array into another which is can contain one more item. It copies each item one-by-one. That must be taking a lot of time.

You have a comment to say that Redim Preserve doesn't work. I am surprised about that. It always works for me. If you have found a circumstance where it fails, you could use an array of sufficient size to start with, and use a variable to mark the current highest effective index.

If you can't calculate the final size, you could merge the two techniques, and use your CopyArray routine to increase the array size by, say, 1000 items at a time. That way the slow item-by-item copy would only occur 0.1% of the previous number of times.

 

by: roos01Posted on 2009-01-31 at 02:04:52ID: 23516121

Im not sure if this one helps you out and it is also not so dynamic as your macro still I think it will do the job. I did a test and it took about 11 minutes to get 1 million combinations on a machine with 2800 Athlon processor

wich is about 1430 minutes (approx 24 hours)

regards,
Jeroen

Dim i, j, k, l, m, n, o, p, q, r, s, t As Long
Dim RowsA, RowsB, RowsC, RowsD, RowsE, RowsF, RowsG, RowsH, RowsI, RowsJ, RowsK, Rw As Long
Dim MyCol1, MyCol2, MyCol3, MyCol3, MyCol4, MyCol5, MyCol6, MyCol7, MyCol8, MyCol9, MyCol10, MyCol11 As Collection
Dim strtime, Endtime, strtRow As Long
Dim ws1, ws2 As Worksheet
Dim startTime As Long
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set ws1 = Sheets("Combinations")
startTime = Now
'Set ws2 = Sheets("Target")
strtRow = 2 'define row to start
RowsA = Application.CountA(ws1.Range("2:2"))
RowsB = Application.CountA(ws1.Range("3:3"))
RowsC = Application.CountA(ws1.Range("4:4"))
RowsD = Application.CountA(ws1.Range("5:5"))
RowsE = Application.CountA(ws1.Range("6:6"))
RowsF = Application.CountA(ws1.Range("7:7"))
RowsG = Application.CountA(ws1.Range("8:8"))
RowsH = Application.CountA(ws1.Range("9:9"))
RowsI = Application.CountA(ws1.Range("10:10"))
RowsJ = Application.CountA(ws1.Range("11:11"))
RowsK = Application.CountA(ws1.Range("12:12"))
'RowsB = ws1.Cells(strtRow + 1, 2).End(xlUp).Row
'RowsC = ws1.Cells(strtRow + 2, 3).End(xlUp).Row
 
    
Set MyCol1 = New Collection
Set MyCol2 = New Collection
Set MyCol3 = New Collection
Set MyCol4 = New Collection
Set MyCol5 = New Collection
Set MyCol6 = New Collection
Set MyCol7 = New Collection
Set MyCol8 = New Collection
Set MyCol9 = New Collection
Set MyCol10 = New Collection
Set MyCol11 = New Collection
 
For i = 2 To RowsA
    MyCol1.Add Cells(strtRow, i)
Next
For i = 2 To RowsB
    MyCol2.Add Cells(strtRow + 1, i)
Next
For i = 2 To RowsC
    MyCol3.Add Cells(strtRow + 2, i)
Next
For i = 2 To RowsD
    MyCol4.Add Cells(strtRow + 3, i)
Next
For i = 2 To RowsE
    MyCol5.Add Cells(strtRow + 4, i)
Next
For i = 2 To RowsF
    MyCol6.Add Cells(strtRow + 5, i)
Next
For i = 2 To RowsG
    MyCol7.Add Cells(strtRow + 6, i)
Next
For i = 2 To RowsH
    MyCol8.Add Cells(strtRow + 7, i)
Next
For i = 2 To RowsI
    MyCol9.Add Cells(strtRow + 8, i)
Next
For i = 2 To RowsJ
    MyCol10.Add Cells(strtRow + 9, i)
Next
For i = 2 To RowsK
    MyCol11.Add Cells(strtRow + 10, i)
Next
    Rw = 1
    col = 4
    With ActiveSheet
        For Each j In MyCol1
            For Each k In MyCol2
                For Each l In MyCol3
                    For Each m In MyCol4
                        For Each n In MyCol5
                            For Each o In MyCol6
                                For Each p In MyCol7
                                    For Each q In MyCol8
                                        For Each r In MyCol9
                                            For Each s In MyCol10
                                                For Each t In MyCol11
                                                '.Cells(Rw, col) = j & k & l
                                                strValue = j & k & l & m & n & o & p & q & r & s & t
                                                Debug.Print strValue
                                                Rw = Rw + 1
                                                If Rw = 1000000 Then
                                                    Endtime = Now
                                                    'MsgBox Format(Endtime - startTime, "hh:mm:ss")
                                                End If
                                                Next t
                                            Next s
                                        Next r
                                    Next q
                                Next p
                            Next o
                        Next n
                    Next m
                Next l
            Next k
        Next j
    End With
    
 Set MyCol1 = Nothing
 Set MyCol2 = Nothing
 Set MyCol3 = Nothing
 Set MyCol4 = Nothing
 Set MyCol5 = Nothing
 Set MyCol6 = Nothing
 Set MyCol7 = Nothing
 Set MyCol8 = Nothing
 Set MyCol9 = Nothing
 Set MyCol10 = Nothing
 Set MyCol11 = Nothing
 Endtime = Now
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
MsgBox Format(Endtime - startTime, "hh:mm:ss")
End Sub

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:

Select allOpen in new window

 

by: piyushdabombPosted on 2009-01-31 at 10:03:10ID: 23517843

Graham -

Interesting. Can I request you to update the macro so I can give it a try if it doesn't take you a significant amount of time. Regarding re dim preserve,it will not work on multi dimensional arrays 2nd dimension.

Roos -

Why would your code be any faster? Can you please explain?

To all -
You will notice that after I take the low level combinations, I am takin the sum of whatever is in that array and doing a comparison with it. During the run (and by the way, it is still running on it's 20 millionth combination... Jesus!), you will notice that if you break the code, it always stops in that summing loop. Can I somehow make that find value loop faster? Let me know.

 

by: piyushdabombPosted on 2009-01-31 at 10:20:57ID: 23517922

roos - I also noticed that you are on generating the combinatins and not saving the sum values. Can I request you incorporate the sum of the values with it? I almost feellike your code will slow down. Try it out!  

 

by: GrahamSkanPosted on 2009-01-31 at 14:30:31ID: 23518884

I haven't fully interpreted all your code, so I can't easily modify it to demonstrate. I have but a breakpoint in the CopyCode routine and stooped it a few times. The second dimension seems to vary less often tha the first, so you could swap them around so that you can usual just Redim  and only copy when the new first dimension is to change.

Another way would be to use a token - perhaps an integer variable (an index to a fixed string array)  - when manipulating the data, and only translate it to the long text string at the end.

I must ask what your objective is. I can't help thinking that there must be a better way than producing 135 million lines of text.

 

by: piyushdabombPosted on 2009-01-31 at 15:41:23ID: 23519175

Graham,

Sure. If you take al ook at the code, whats its essentially doing is that for every single low level attribute, it stores the sum of all the "Perceived Values" and "Cost/Empl. Values" into an array in addition to the combination.

No, I'm not saving all 135 Million combinations, their perceived values and their "Cost/Empl. Values". Essentially, once I get the some of the cost/empl. values, I round it to the nearest 10 digit. I then check to see if that rounded value already exists in a collection. If it does, I compare the perceived value of the current combination to the one already stored in the colleciton. If the value of the current combinations perceived value is greater than the one stored, I save the new value.

Once all these combinations are run, i esentially shouldn't get more than 65K values of maximum perceived values to every single rounded $10 cost.

I want to show you a piece of code another developer from Experts Exchange did for me some time ago (I didn't use it because it was too complicated for me to understand). Anyone possibly explain what he did and why his combinations generations are soo much quicker (its ridiculous)?

To run it, just select the combinations you want to use in the attributes and click the button. Note the combination value in the task bar.

You developers are seriously geniuses at this stuff...After writing code for a year in my life (heh), I'm now learning to be a quicker developer (as pathetic as it sounds).

Anyway, somehow I need to take the code provided by roos or whats in the enclosed macro and do what I did in my macro. Both roos' and the enclosed macro genrate the combinations. I just need to implement that generation, capture the sum and save the value.


 

by: piyushdabombPosted on 2009-01-31 at 17:05:05ID: 23519485

Team,

Okay, what I've done is used the "CombinatrixRedux" matrix provided in the previous post to essentially redo my macro.

Enclosed is the new macro. Anyone know why my status bar isn't updating anymore? Can someone help with this? It'd be nice to know how long it would take to run the number of combinations "dynamically" and where I am wiht it.

This is the status bar that was working previously:
Application.StatusBar = "Now posting combination " & i & " of " & nMax

 

by: piyushdabombPosted on 2009-02-03 at 07:38:42ID: 31540515

I am giving a "B" solely because of the quality inputs provided by the respondents. The code, while it works for 1 solution is not flexible to my needs. I've posted my code for others to see. Its much more flexible and generates all the combinations in the same amount of time as the code provided above.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...