Need help Urgently - vba looping

franciscocorrea

New Member
Joined
Oct 31, 2012
Messages
11
Hello everyone,

I want Column B to reflect the parent of Column A, using VBA. I think i should make an iteration, removing digits of Column A until the value is found in Column A. Here an example:

Column A
Column B
1
11
1111
12
1222
122224

<tbody>
</tbody>

I want the following outcome:

Column A
Column B
1
11
1
1111
11
12
1
1222
12
122224
1222

<tbody>
</tbody>

Thanks!!

Best regards,
Francisco
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hello everyone,

I want Column B to reflect the parent of Column A, using VBA. I think i should make an iteration, removing digits of Column A until the value is found in Column A. Here an example:

I want the following outcome:

Column AColumn B
1
111
111111
121
122212
1222241222

<tbody>
</tbody>
I think this will do what you want. Put the following formula in cell B2 and copy it down to the end of your data...

=IF(LEN(A2)<=LEN(A1),1,A1)
 
Upvote 0
Thanks for your help!

but I need to do it iteratly...because sometimes I may have to remove 3, 4, 5 .... digits. So thats why i want to use VBA, 1) have to remove one digit, 2) see if that new number is on Column A 3) if it is not, remove another digit, until it finds an equal number on Column A.
 
Upvote 0
but I need to do it iteratly...because sometimes I may have to remove 3, 4, 5 .... digits. So thats why i want to use VBA, 1) have to remove one digit, 2) see if that new number is on Column A 3) if it is not, remove another digit, until it finds an equal number on Column A.

I am not following you on this... can you show what you mean with an original short list followed by one, two or whatever number of follow-up lists that show what results you are looking for given the changes you are trying to describe?
 
Upvote 0

Forum statistics

Threads
1,218,277
Messages
6,141,498
Members
450,366
Latest member
spasmex97

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