so basically, I wish to write a programme to do the below for me.
assume there are only 4 cells with values that follow the "colon"
a1.:2
a2.:3
a3.:4
a4.:5
so what i wanna do is to see which of these figures(i.e. 2,3,4,5) can add up to 7 (or any number that i assign)
the program should run all possibilities of combinations, add the figures up to see if there are any matches, so. for instance
2+3
2+4
2+5 = 7
3+4 = 7
3+5
4+5
2+3+4
2+3+5
2+4+5
3+4+5
2+3+4+5
The problem should be able to generate a list of possibilities like above, sum them, and tell me 2&5, 3&4; (cell a1+a4; or cell a2+a3 ) add to 7.
Finally, i want the programme gives the result by highlighting the cells (or any other better way) for result.
there are a couple of issues that i have encountered.
1. after I read all those figures in the selected cells to an array and identified the possible combinations. how can I manipulate the corresponding cells for a show of result? in other words, if array[1] is the match, how can i highlight the corresponding cell-a1 for instance.
2. i wish to write a multiple-layer-for-loop for this, but not sure how to make a for-loop that can goes first from a search for combinations of 2 figures, and then for 3 figures, 4,5,6 and so on until it finds matches. and does it mean if i want to make a search for a combinations of 10 figures, i will need to make a 10-layer for-loop?
3. if I run a search for a pool of 100 cells. for a maximum of combinations of 10 numbers, the mulitple-layer-for-loop could become a enormous structure which I believe eliminating duplicated combinations due to the for-loop is necessary(e.g 2+3 = 3+2) , inefficiency is quite a issue.
really SORRY for asking such a long question, i am absolutely a newbie on vba(though with quite plenty of experience on pascal, yea, learnt in high school), but somehow i think if i can able to write up a programme like that, that would bring a lot of ease to my job, saving me a lot of time. having thought about this for a long time, but can't even figure out how to build the basic algorithms.
ths alot in advance.
Bookmarks