excel - Removing the border lines in a worksheet when code has been run -
i have code looks external file , copy/pastes rows contain particular condition current workbook. example searching singapore
in external workbook called active master project file , copy rows containing singapore
current workbook open.
a problem occurs when run same code twice, border line exist on last row of worksheet. example when run code, copy paste information containing singapore
current worksheet called "new upcoming projects":
however, when run code again create border line on each column such image shown below:
and code have is:
sub updatenewupcomingproj() dim wb1 workbook, wb2 workbook dim ws1 worksheet, ws2 worksheet dim copyfrom range dim lrow long '<~~ not integer. might give error in higher versions of excel dim strsearch string set wb1 = application.workbooks.open("u:\active master project.xlsm") set ws1 = wb1.worksheets("new upcoming projects") strsearch = "singapore" ws1 '~~> remove filters .autofiltermode = false '~~> assuming names in col '~~> if not change below whatever column letter lrow = .range("a" & .rows.count).end(xlup).row .range("a1:a" & lrow) .autofilter field:=1, criteria1:="=*" & strsearch & "*" set copyfrom = .offset(1, 0).specialcells(xlcelltypevisible).entirerow end .autofiltermode = false end '~~> destination file set wb2 = thisworkbook set ws2 = wb2.worksheets("new upcoming projects") ws2 if application.worksheetfunction.counta(.cells) <> 0 lrow = .cells.find(what:="*", _ after:=.range("a1"), _ lookat:=xlpart, _ lookin:=xlformulas, _ searchorder:=xlbyrows, _ searchdirection:=xlprevious, _ matchcase:=false).row else lrow = 2 end if copyfrom.copy .rows(lrow) .rows.removeduplicates array(2), xlno end end sub
is there improvement or additional codes have add in border line disappear?
i assume formatting coming source worksheet. if so, pastespecial
paste values, keeping destination formatting. so, replace
copyfrom.copy .rows(lrow)
with
copyfrom.copy .rows(lrow).pastespecial xlpastevalues, xlpastespecialoperationnone, false, false
if need formatting source sheet, can use xlpasteallexceptborders
instead of xlpastevalues
.
Comments
Post a Comment