excel - Using the following code it populates all cells in the table that are blank -
i have following code , works great except 1 thing when used finds every blank field in table , inserts value of field above it. need fill fields above rows inserted code.
sub ercacmpcleanup() 'cleans erca_cmp worksheet , creates records comma delimited dim x long, lastrow long, range, table range, data() string const delimiter string = ", " const delimitedcolumn string = "a" const tablecolumns string = "a:o" const startrow long = 2 application.screenupdating = false activeworkbook.worksheets("erca_cmp").visible = true activeworkbook.worksheets("erca_cmp").activate lastrow = columns(tablecolumns).find(what:="*", searchorder:=xlrows, _ searchdirection:=xlprevious, lookin:=xlformulas).row x = lastrow startrow step -1 data = split(cells(x, delimitedcolumn), delimiter) if ubound(data) > 0 intersect(rows(x + 1), columns(tablecolumns)).resize(ubound(data)).insert xlshiftdown end if if len(cells(x, delimitedcolumn)) cells(x, delimitedcolumn).resize(ubound(data) + 1) = worksheetfunction.transpose(data) end if next **lastrow = cells(rows.count, delimitedcolumn).end(xlup).row on error resume next set table = intersect(columns(tablecolumns), rows(startrow).resize(lastrow - startrow + 1)) if err.number = 0 table.specialcells(xlblanks).formular1c1 = "=r[-1]c" columns(delimitedcolumn).specialcells(xlformulas).clear table.value = table.value end if on error goto 0** end sub
the issue in last few rows code needs fill blanks in inserted rows not blank fields in table.
any appreciated.
modified code check if cells in b:0 null. think intersect not correct in case don't want apply cells.
note 1: there better solution i'm not familiar complete vba
note 2: if put application.screenupdating = false
should set true
@ end of program too.
sub ercacmpcleanup() 'cleans erca_cmp worksheet , creates records comma delimited dim x long, lastrow long, range, table range, data() string dim flgval boolean, rcntr integer, ccntr integer, rownum integer const delimiter string = ", " const delimitedcolumn string = "a" const tablecolumns string = "a:o" const startrow long = 2 application.screenupdating = false activeworkbook.worksheets("erca_cmp").visible = true activeworkbook.worksheets("erca_cmp").activate lastrow = columns(tablecolumns).find(what:="*", searchorder:=xlrows, _ searchdirection:=xlprevious, lookin:=xlformulas).row x = lastrow startrow step -1 data = split(cells(x, delimitedcolumn), delimiter) if ubound(data) > 0 intersect(rows(x + 1), columns(tablecolumns)).resize(ubound(data)).insert xlshiftdown end if if len(cells(x, delimitedcolumn)) cells(x, delimitedcolumn).resize(ubound(data) + 1) = worksheetfunction.transpose(data) end if next 'modification start question 'flgval turns true if cells b:o not empty flgval = false range("a1").activate rcntr = 0 lastrow - 1 ccntr = 1 14 if activecell.offset(0, ccntr).value <> "" flgval = true exit end if next if flgval = false ccntr = 1 14 activecell.offset(0, ccntr).formular1c1 = "=r[-1]c" next else flgval = false end if activecell.offset(1, 0).activate next '**lastrow = cells(rows.count, delimitedcolumn).end(xlup).row 'on error resume next 'set table = intersect(columns(tablecolumns), rows(startrow).resize(rownum - startrow)) 'if err.number = 0 ' table.specialcells(xlblanks).formular1c1 = "=r[-1]c" ' columns(delimitedcolumn).specialcells(xlformulas).clear ' table.value = table.value 'end if 'on error goto 0** application.screenupdating = true end sub
Comments
Post a Comment