Monday 15 August 2011

Excel VBA Filling Columns with Select Criteria -



Excel VBA Filling Columns with Select Criteria -

i've been trying hard vba code work. i'm there, have no clue how 1 thing.

this want do:

i need fill 4 pairs of adjacent columns. first column in pair needs have, in descending order, set of numbers, illustration 30 0. end @ 0, can start @ different numbers. sec column in pair needs have max of xx in first cell below header, , min of yy in lastly cell. in between, can have number, doesn't matter.

what happening this:

i able populate each pair on own , together, everytime populate pair of columns next pair, first pair (on left), gets first column shifted downwards 1 cell, , cell below first column's header blank. not happen lastly pair populated.

i need have first column in each pair not shifted downwards 1 cell. create sense anybody?

here's bit of code:

sub macro2() dim name string dim maxscores range dim maxtotal integer dim minnum integer dim sub1num integer dim sub2num integer dim sub3num integer dim sub4num integer dim minsstot integer dim minsssub1 range dim minsssub2 range dim minsssub3 range dim minsssub4 range dim maxsstot integer dim maxsssub1 integer dim maxsssub2 integer dim maxsssub3 integer dim maxsssub4 integer dim bottomrow long dim bottomrowsub1 long dim bottomrowsub2 long dim bottomrowsub3 long dim bottomrowsub4 long dim lastsstot range testname = worksheets("lookups").cells(2, 1).value 'sub1' sub1num = application.worksheetfunction.vlookup(name, maxscores, 4, false) minnum = 0 maxsssub1 = 80 worksheets("subscores").activate = minnum sub1num selection.insert shift:=xldown, copyorigin:=xlformatfromleftorabove range("a2").select activecell.formular1c1 = minnum + next cells(2, 2).value = maxsssub1 bottomrowsub1 = range("a" & rows.count).end(xlup).row range("b2").autofill destination:=range("b2:b" & bottomrowsub1) set minsssub1 = range("b2").end(xldown) minsssub1 = 15 'sub2' sub2num = application.worksheetfunction.vlookup(name, maxscores, 5, false) minnum = 0 maxsssub2 = 85 worksheets("subscores").activate = minnum sub2num selection.insert shift:=xldown, copyorigin:=xlformatfromleftorabove range("c2").select activecell.formular1c1 = minnum + next cells(2, 4).value = maxsssub2 bottomrowsub2 = range("c" & rows.count).end(xlup).row range("d2").autofill destination:=range("d2:d" & bottomrowsub2) set minsssub2 = range("d2").end(xldown) minsssub2 = 15 'sub3' sub3num = application.worksheetfunction.vlookup(name, maxscores, 6, false) minnum = 0 maxsssub3 = 50 worksheets("subscores").activate = minnum sub3num selection.insert shift:=xldown, copyorigin:=xlformatfromleftorabove range("e2").select activecell.formular1c1 = minnum + next cells(2, 6).value = maxsssub3 bottomrowsub3 = range("e" & rows.count).end(xlup).row range("f2").autofill destination:=range("f2:f" & bottomrowsub3) set minsssub3 = range("f2").end(xldown) minsssub3 = 15 'sub4' sub4num = application.worksheetfunction.vlookup(name, maxscores, 7, false) minnum = 0 maxsssub4 = 35 worksheets("subscores").activate = minnum sub4num selection.insert shift:=xldown, copyorigin:=xlformatfromleftorabove range("g2").select activecell.formular1c1 = minnum + next cells(2, 8).value = maxsssub4 bottomrowsub4 = range("g" & rows.count).end(xlup).row range("h2").autofill destination:=range("h2:h" & bottomrowsub4) set minsssub4 = range("h2").end(xldown) minsssub4 = 15 end sub

excel vba excel-vba autofill

No comments:

Post a Comment