excel - If column contains number greater than 1, replicate that row that many times -


ok, got working, , added code change column in same loop, final challenge @ q column, contains quantity of items ordered, , if > 1 copy entire row, , paste newly inserted rows many on 1 quantity was. example

josh   smith  soda    1 john   doe    banana  3 tony   brown  cake    1  

would need become

josh   smith  soda    1 john   doe    banana  3 john   doe    banana  3 john   doe    banana  3 tony   brown  cake    1  

my code far is:

sub preplabels() dim long = 3 range("a2").end(xldown).row step 1     if cells(i, "q") > 1         activecell.entirerow.select         selection.copy         selection.insert shift:=xldown     end if end if next end sub 

but failed @ something, first row replicates 7 times or something.

when inserting rows, start @ bottom , work towards top inserted rows not conflict iteration count.

sub preplabels()     dim long, r long, lr long     activesheet   'define worksheet properly!         lr = .cells(rows.count, 1).end(xlup).row         = lr 3 step -1             r = 2 .cells(i, "q").value2                 .cells(i + 1, 1).entirerow.insert                 .cells(i, 1).resize(2, columns.count).filldown             next r         next     end end sub 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -