VBA Paste according to value in cell

cozzagiorgi

New Member
Joined
Jun 27, 2018
Messages
41
Hi

I need to copy stuff from one worksheet to another according to the value of another cell. E.g.

Row A says: Apples, Oranges, Bananas
Row B says: 10, 5, 7

I now need to copy Apples 10x, Oranges 5x, Bananas 7x in Row A on another worksheet.

Any ideas how I could accomplish that?
 
Hey, this works!

But I get a runtime error 1004 when the loop is at the end. I think it tries to loop one time to much. Possible?

Edit: Runtime error only appears if I am still on sheet1. If I am on sheet2 it works without error.
 
Last edited:
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
That is probable because you have no value in column D
You have a value in column C on sheet 1 but no value in column D

The script should be run from sheet 1 the copy from sheet.
 
Upvote 0
Great. Thanks for your help!

Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.

Next time you have a question it's best to give specific details.
I do not understand for example why you would say column A and then say column C
And why you would not say where to start on each sheet.

And I would normally say if any value is in column C not if Apple Orange or Banana
When you really mean any value. We have lots of people say if George or Bob or Jane and that is really what they want. They only want the script to run if George or Bob or Jane is in column C
 
Upvote 0
I will try to be much more specific next time. I thought it was easier working on a simple sample, then understanding the code and going from there.

I do understand your code now. But I could never come up with something like that by myself.
 
Upvote 0
I will try to be much more specific next time. I thought it was easier working on a simple sample, then understanding the code and going from there.

I do understand your code now. But I could never come up with something like that by myself.

Well I always try to read code myself and try to learn more every day.

And with Excel there are always 20 ways to do every thing.
I try to write scripts which may be easy to read. Now my scripts may not always be the fastest way but for me a extra second or two is not a problem. If you want the fastest script in the West which will run in 2.1 milliseconds instead of 2.5 milliseconds then I'm not the man to learn from.

Take care and have a nice day.

Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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