Loop To Last EndPt

ivandgreat

Board Regular
Joined
Jun 20, 2012
Messages
95
Hi,

anyone could help me to have a macro that will loop in a columns when cell data is found empty @ column IDB will search the adjacent value of column IDA @ column IDB until found nothing follows and concatenate the cell value @ column D and put it in column E.

this is the table below,

ItemIDAIDBStorAvail
12000200110
22001200220
32002200430
42004
40
52005200450

<tbody>
</tbody>


The output table below,

ItemIDAIDBStorAvail
1200020011040 / 30 / 20 / 10
2200120022040 / 30 / 20
3200220043040 / 30
42004
4040
5200520045040 / 50

<tbody>
</tbody>


br,
ivan
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Anyone could help me on this. thanks!
Maybe... need a question answered first though. Will there only ever be one empty cell in Column IBD like your sample shows? If not, then show us a sample with two blanks (make sure the 2nd blank is not on the last row) so we can see how to transition between the two blanks.
 
Upvote 0
Maybe... need a question answered first though. Will there only ever be one empty cell in Column IBD like your sample shows? If not, then show us a sample with two blanks (make sure the 2nd blank is not on the last row) so we can see how to transition between the two blanks.

There will be a lot empty value for IDB but i think you could
consider column IDA.

IDA won't have any empty and won't be duplicated.

Thanks a lot.
 
Upvote 0
There will be a lot empty value for IDB but i think you could
consider column IDA.

IDA won't have any empty and won't be duplicated.
Huh? Sorry, that does not make sense to me. My understanding of what you want is to take the value in Stor column (where there is a blank cell in the IDB column) and concatenate it (with a slash delimiter) upward and downward with the value in the Stor column above and below the blank cell, then to concatenate those concatenations with the cells above or below them, and so on (all of which is to go into the Avail column). The problem with that arrangement is knowing what should be done between two blank cells since the order of concatenations is different for cells between them depending on the direction being traveled in from each blank. I have no idea what the IDA column has to do with that process unless there is something about your data that you know and are assuming, for whatever reason, that we know also. If you would provide the example data I asked for in my first message (showing two blanks in the IDB column and data before, between and after them), I think someone here will be able to figure out a solution for you or, at worst, come up with some more questions to clarify things some more.
 
Upvote 0
I just thought that it will start coding to find the empty value on IDB then from there it will get the value to be concatenated with the other rows.

Column IDA will tell you which row it will go next since it will be used to find it in column IDB.

ex. If column IDB found empty, input Stor value at column Avail then from this row IDA have a value of 2004 (carry the Stor value 40), this value will be located on column IDB which found in row 3 and 5, then concatenate with the value carried (40) with Stor value which will give you Avail value of 40 / 30 and 40 / 50, respectively. Then this two rows will look the IDA value, row 5 with 2005 unable to find it in column IDB so stops there, but row 3 with 2002 will find in column IDB at row 2 so it will concatenate the value from Its Avail value, so it will have 40 / 30 / 20 then same loop for the next IDA until found nothing match in column IDB.

hope you could help me on this.

regards,
ivan
 
Upvote 0
2nd Sample with output


ItemIDAIDBStorAvail
1200020011040/30/20/10
2200120022040/30/20
3200220043040/30
420044040
5200520045040/50
62003200620100/20
72007200350100/20/50
82006100100

<tbody>
</tbody>
 
Upvote 0
2nd Sample with output


Item
IDA
IDB
Stor
Avail
1
2000
2001
10
40/30/20/10
2
2001
2002
20
40/30/20
3
2002
2004
30
40/30
4
2004
40
40
5
2005
2004
50
40/50
6
2003
2006
20
100/20
7
2007
2003
50
100/20/50
8
2006
100
100

<TBODY>
</TBODY>
I have been looking at your question on-and-off for a couple of days now and I cannot get my head around the mechanism used to fill in the Avail column. For the first blank in IDB at row 4, it looks like you check the number in IDA to its left (on row 4) and see if the number in IBD above it (row 3) is the same... if so, you concatenate the Stor values, then you check the IDA value to the left of that match (on row 3) with the IDB value above it (on Row 2) and if they match, you do another concatenation and you keep repeating that process until (I guess) the match stop or you reach the top of the table. However, that does not seem to be the mechanism you follow for the second blank (on row 8)... for that one, you do not attempt to match the value to its left with the value above it... you travel up column IDB until you find a match on row 6 and then, instead of traveling upward looking for matches like you did for the first blank, you travel back downward until you hit the blank where you stop. Also you did not do like I asked originally and show me number below the last blank (which might have given a clue to what is going on) so I do not know what should happen for values below the second blank. Can you clarify the mechanism (in detail please) as to how you decide what is being concatenated where?
 
Upvote 0
Hi Rick,

This is show the mechanic works,

First locate empty value in IDB, here found 2 item, in item 4 and 8, record the value in col Stor (40 and 100 respectively)
-@ first item found (item 4 with value 40) copy it @ col Avail then identify the value in IDA which are in the same row, which is 2004, here you have to locate the value in IDB
- With IDA value 2004, were found in item 3 and 5,
- Do first @ item 3, concatenate the recorded value (from item 4 with value 40) with value in Stor, which is 30, you'll have 40 / 30, then identify again the value in IDA (same row), which is 2002, locate it in col IDB (found in item 2), concatenate the recorded value, yo'll have 40 / 30 / 20, do the same loop until the value in IDA were unable to found in IDB.
- Still with IDA value 2004, if found nothing go to the next value, which is now IDB value 2005 (item 5), do the same loop.
- After finishing the above loop, go to the next empty value @ IDB and do the same logic as above.

End loop when IDB and IDA is both empty.

thanks in advance.

br,
ivan
 
Upvote 0

Forum statistics

Threads
1,217,889
Messages
6,139,224
Members
450,186
Latest member
MarkMMcGuireNEUK

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top