excel - How to clear duplicate-named columns? -
actually have find column named "account" , have delete data entered in column. lets column name "account" in cell "b9" , values have been entered till "b30"(it variable), have delete data "b10"to "b30". , if have 1 more column in name of "account", have same column also.
i have coded 1 column. want write multiple columns.
here coding,
private sub commandbutton1_click() dim xlapp excel.application dim wb workbook dim findrow range dim ad string dim accell string dim de string dim lad string dim col integer dim rw integer dim r integer dim rw2 integer dim myrange range on error goto errhandler: msgbox "please browse document" set xlapp = createobject("excel.application") filestr1 = application.getopenfilename() workbooks.open filename:=filestr1 , notify:=false xlapp set rng1 = activesheet.usedrange.find("account", , xlvalues, xlwhole) col = rng1.column 'msgbox col' rw = rng1.row 'msgbox rw' r = rw + 1 'msgbox r' ad = rng1.address 'msgbox ad' activesheet.range(ad).activate activecell.offset(1, 0).activate rw2 = activecell.row de = activecell.address 'msgbox de' activesheet.cells(rows.count, col).end(xlup).activate lad = activecell.address 'msgbox lad' set myrange = activesheet.range(de & ":" & lad) myrange.select selection.clearcontents on error goto errhandler: filestr4 = application.getsaveasfilename("removedaccno") activeworkbook.saveas (filestr4) on error goto errhandler: end exit sub errhandler: msgbox ("user cancelled.") end sub
you can findnext method
this method "continues search begun find method"
also, try not use select
, activate
. lot of datas, it's bad performance.
finally, may check rng1
content after find
avoid range error line :
if not rng1 nothing
Comments
Post a Comment