excel vba - Deleting data ranges from one workbook using code in another workbook -


i having heck of time having code 1 workbook ("w1") open workbook ("w2") , perform deletions in w2. when run it, selects ranges in w2 not delete selection. figured out must explict naming w2 deletions, i'm getting lost it. appreciated.

my code follows:

sub clear_fm_contents()  dim f filedialog dim varfile variant dim path variant  'prompt user select excel file import set f = application.filedialog(msofiledialogfilepicker)  'error handling file selector if f.show = false     msgbox "you clicked cancel in file dialog box."     end end if  'set path of user selected file each varfile in f.selecteditems     path = varfile next  'create excel object dim xlapp excel.application set xlapp = createobject("excel.application") xlapp.visible = true  'open selected excel file xlapp.workbooks.open path, true, false  'clear template inputs xlapp.activeworkbook     .sheets("mrkt data").select     xlapp.activeworkbook.activesheet         .range("e36,e5,e7,e10,e13,e17,e39,j7:j11,j13:j20,j24:j29,j31:j33,j35,o21").select         .range("o21").activate         xlapp.activeworkbook.activesheet.selection.clearcontents     end     'close excel file     activeworkbook.save     activeworkbook.close   end 'close excel xlapp.quit 'eliminate xl app object memory set xlapp = nothing  msgbox "model inputs cleared" end sub 

if select works, replace clearcontents instead , delete 2 lines under try activate , clear. suspect issue activate , o21 being cleared not others. delete activate line trying clean instance of select not needed.

with xlapp.activeworkbook.activesheet     .range("e36,e5,e7,e10,e13,e17,e39,j7:j11,j13:j20,j24:j29,j31:j33,j35,o21").clearcontents end 

instead of

with xlapp.activeworkbook.activesheet     .range("e36,e5,e7,e10,e13,e17,e39,j7:j11,j13:j20,j24:j29,j31:j33,j35,o21").select     .range("o21").activate     xlapp.activeworkbook.activesheet.selection.clearcontents end 

you compress with , on 1 line, wide here didn't it.

you should take @ this post not using select.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -