Link to home
Start Free TrialLog in
Avatar of nbozzy
nbozzy

asked on

how to insert rows and copy cells in Excel VBA

Using VBA code, I need to go through a range of cells in column P, and where column P contains data, I need to check the quantity on that row (col H). If the quantity on that row is greater than 1.......

Here's the part I don't know how to do:.....

If the quantity on that row is greater than 1, Insert (quantity minus one) rows BELOW that row, AND copy down the data in cells I & J, AND make those cells in column Q yellow interior.

For example, if the code discovers that cell P20 has data and cell H20 = 4, then insert new rows 21, 22, and 23. Copy I20:J20 down to I23:J23. Make Q20:Q23 yellow interior. Then, the next cell in the range and repeat.

Thanks!
Avatar of StephenJR
StephenJR
Flag of United Kingdom of Great Britain and Northern Ireland image

Could you post a sample workbook please?
Avatar of nbozzy
nbozzy

ASKER

EE-sample.xls
Attached. Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Tracy
Tracy
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nbozzy

ASKER

Thank you both! Both solutions worked, so I will split points.
StephenJR: yes, I do want yellow only if quantity is 1, but I can modify the code to accommodate that. ;)
Broomee9: your code did leave the copy "marquis" visible along with cells selected, but I know how to fix those things.

I appreciate the help and the new knowledge!
Avatar of nbozzy

ASKER

I didn't choose a "Best Solution" because that depends upon the particular user. Thanks!