In Excel VBA, How to add automatic value in range -
i have list of jobs in sheet1 , 5 employee names in sheet2. when run macro should automatically find out count of jobs , should divide jobs equally employees , should paste employees jobs.
here code below
dim x integer dim y integer  range(selection, selection.end(xldown)).select x = selection.rows.count y = application.roundup(x / 5, 0) here, how give y value in range?
ok try this:
sub test()     dim jrng range, nrng range     dim long, x long, y long j long: j = 1      sheet1 '~~> change suit         '~~> change range address suit         set jrng = .range("a1", .range("a" & .rows.count).end(xlup))'~~> contains jobs         set nrng = .range("c1", .range("c" & .rows.count).end(xlup))'~~> contains names         y = jrng.rows.count'~~> number of jobs         '~~> number of jobs per name         x = application.worksheetfunction.roundup(jrng.rows.count / nrng.rows.count, 0)         = 1 y step x             .cells(i, "b").resize(x) = nrng(j)             j = j + 1         next     end end sub this base logic. can adapt suit needs.
 in code, jobs listed in column a  , names in column c.
 output populated in column b.
note: works if number jobs divisible number of names.
 have specify how want divide excess jobs , adjust code accordingly.
Comments
Post a Comment