Hi everyone!
I just created a FUNCTION to find the column number of a cell in other BOOK depending of two variables. For 100 cells it takes 3 minutes to calculate!
THIS IS MY CODE:
![]()
Please Login or Register to view this content.
Hi everyone!
I just created a FUNCTION to find the column number of a cell in other BOOK depending of two variables. For 100 cells it takes 3 minutes to calculate!
THIS IS MY CODE:
![]()
Please Login or Register to view this content.
Last edited by LuisEngineer; 08-23-2017 at 07:39 PM.
Deleted while OP complied to Forum Rules.
Last edited by bakerman2; 08-24-2017 at 11:48 AM.
Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.
I would suggest that you come up with a better searching algorithm. As programmed, it looks like a very inefficient "start in the upper left corner and go across and down until it finds the cell that matches the two criteria". I think a better search algorithm could improve the performance of this.
First thing I notice, it appears that you are only going to return a value from the row which has takt in the leftmost column. As presently programmed, your search algorithm wastes a lot of time/effort searching across rows that do not have takt in the first column of that row. I would structure the algorithm so that it first searches for takt in the first column. Once the algorithm knows which row takt is in, then look for the column in that row that contains wagon.
Does that make sense? It appears that you already know how to code a basic linear search algorithm, so can I assume you can rearrange your loops to change the search order?
Originally Posted by shg
Hey! Thanks for your help, I've been trying to do what you said but I can't get it. Can you help me showing how would you do the arrange please?
![]()
I'd be curious what you tried. You seem to know For...Next loops and Block If's and such, so it seems like it should have been fairly straightforward. I would have expected like this code snippet:![]()
Please Login or Register to view this content.
I would even lose the column search.
![]()
Please Login or Register to view this content.
Last edited by bakerman2; 08-24-2017 at 02:08 PM.
I am sorry guys but why would anyone search through a whole lot of cells looking for specific text?
Surely you would use the Find function?
What am I missing?
![]()
Please Login or Register to view this content.
Last edited by mehmetcik; 08-24-2017 at 02:44 PM.
My General Rules if you want my help. Not aimed at any person in particular:
1. Please Make Requests not demands, none of us get paid here.
2. Check back on your post regularly. I will not return to a post after 4 days.
If it is not important to you then it definitely is not important to me.
mehmetcik: I did not suggest the .Find method because I was not sure how well it would work for this kind of 2D lookup, especially if there are multiple instances of wagon in the table and the goal of the lookup is to find which instance of wagon is in the takt row. The OP really hasn't given enough information for me to suggest how to use .Find in this situation (though that could easily be because I don't use .Find enough to see how to use it here).
For that matter, why use VBA at all. I expect there is a way to combine INDEX() and MATCH() functions to perform this lookup without VBA. That could also help, just because VBA requires a certain overhead that can contribute to poor performance. I guess we are just working from the OP's starting place.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks