excel - Create new worksheet based on text in coloured cells, and copy data into new worksheet -


i have large data set need manipulate , create individual worksheets. within column b cells coloured green make new worksheet for. please see screen shot.

have characters somewhere...

for example create worksheets titled "shopping" & "retail". once worksheet created, copy data between "worksheet title" (green cells) columns ("b:c") & ("ai:bh") please see screen shot below expected output;

enter image description here

the code have far below can see not complete not know how go extracting data between "green cells".

sub wrksheetadd()  dim r range dim long dim lr long worksheets("ring phased").select  lr = range("b65536").end(xlup).row set r = range("b12:b" & (lr))  = r.rows.count 1 step -1     r.cells(i, 1)         if .displayformat.interior.colorindex = 35         msgbox         worksheets.add(after:=worksheets(worksheets.count)).name = cells (i,1).value         worksheets("ring phased").select         end if     end next  end sub 

any around appreciated.

sorry taking while this, i've been busy last few days, haven't had time on stackoverflow.

anyway, way i'd go store found values in array, , loop through array in order find distance between them.

the following code works me, using simplified data, think principle sound:

option explicit option base 0  sub wrksheetadd()    dim r range, c range   dim long: = 0   dim cells_with_color() range: redim cells_with_color(1)    worksheets("ring phased")     ' since doesn't seem first cell want copy colored, hardcode location here.     ' saves having test if array empty later.     set cells_with_color(i) = .range("b12")     = + 1     set r = range(.range("b13"), .range("b" & .cells.rows.count).end(xlup))      ' put cells color in defined range array     each c in r       if c.displayformat.interior.colorindex = 35         if > ubound(cells_with_color)           redim preserve cells_with_color(ubound(cells_with_color) + 1)         end if         set cells_with_color(i) = c         = + 1       end if     next      ' loop through array, , copy previous range value current 1 new worksheet     ' reset counter first, start @ 1, since first range-value (0 in array) start of started checking     ' (hmm, reusing variables may bad practice >_>)     = 1     while <= ubound(cells_with_color)       worksheets.add(after:=worksheets(worksheets.count)).name = cells_with_color(i).value       ' set range copy - in copy-statement, makes easier read       set r = .rows(cstr(cells_with_color(i - 1).row) + 1 & ":" & cstr(cells_with_color(i).row))       ' change destination whereever want on new sheet. think has in column one, though, since copy entire rows.       ' if want refine bit, change whatever set r in previous statement.       r.copy destination:=worksheets(cstr(cells_with_color(i).value)).range("a1")       = + 1     wend   end end sub 

it lacks error-checking ought in there, i'll leave exercise figure out. believe functional. luck!


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -