copy down based on value

donniedorian

Board Regular
Joined
May 27, 2015
Messages
133
Hello,

I need in d2 each cell in b:b for as many times as corresponding in column c:c.

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]A
[/TD]
[TD]B
[/TD]
[TD]C
[/TD]
[TD]D
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]A12
[/TD]
[TD]2
[/TD]
[TD]A12[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]A13
[/TD]
[TD]4
[/TD]
[TD]A12
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]A14
[/TD]
[TD]6
[/TD]
[TD]A13
[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]A15
[/TD]
[TD]8
[/TD]
[TD]A13
[/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD]A16
[/TD]
[TD]2
[/TD]
[TD]A13
[/TD]
[/TR]
[TR]
[TD]7
[/TD]
[TD]A17
[/TD]
[TD]1
[/TD]
[TD]A13
[/TD]
[/TR]
[TR]
[TD]8
[/TD]
[TD][/TD]
[TD][/TD]
[TD]A14
[/TD]
[/TR]
[TR]
[TD]9
[/TD]
[TD][/TD]
[TD][/TD]
[TD]A14[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG05Jun05
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range("C2", Range("C" & Rows.Count).End(xlUp))
c = 2
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    Cells(c, 4).Resize(Dn.Value) = Dn.Offset(, -1).Value
    c = c + Dn.Value
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Try this:-
Code:
[COLOR=Navy]Sub[/COLOR] MG05Jun05
[COLOR=Navy]Dim[/COLOR] Rng [COLOR=Navy]As[/COLOR] Range, Dn [COLOR=Navy]As[/COLOR] Range, c [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long[/COLOR]
[COLOR=Navy]Set[/COLOR] Rng = Range("C2", Range("C" & Rows.Count).End(xlUp))
c = 2
[COLOR=Navy]For[/COLOR] [COLOR=Navy]Each[/COLOR] Dn [COLOR=Navy]In[/COLOR] Rng
    Cells(c, 4).Resize(Dn.Value) = Dn.Offset(, -1).Value
    c = c + Dn.Value
[COLOR=Navy]Next[/COLOR] Dn
[COLOR=Navy]End[/COLOR] [COLOR=Navy]Sub[/COLOR]
Regards Mick


I try to run the macro but it gives me Error 1004! what else should I do?
 
Upvote 0
Did you try to run the code, on the Data in your thread
If so and it failed, does your data Format show :-

The Text to copy down is in columns "B", The Count for each set of numbers is in column "C" and the results should show in column "D", And the Actual Data starts on row 2

If not please confirm your layout !!!
Perhaps your actual data starts in column "A" ????
 
Upvote 0
Did you try to run the code, on the Data in your thread
If so and it failed, does your data Format show :-

The Text to copy down is in columns "B", The Count for each set of numbers is in column "C" and the results should show in column "D", And the Actual Data starts on row 2

If not please confirm your layout !!!
Perhaps your actual data starts in column "A" ????

Yes the data starts in column A,

Now works like charm, sorry for messing up,
Thanks a lot
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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