Excel VBA - Making a macro valid for all worksheets in workbook -


i have workbook several sheets, (file1, file2, file3, etc), , i'm working on macro parse external file , paste contents in active worksheet. issue make pastestart below not specific work on any active worksheet, not file1, without specifying name. tried using sthg variable = activesheet.name runtime error 242.

sub import1()  dim wb1 workbook dim wb2 workbook dim sheet worksheet dim pastestart range   application.screenupdating = false set wb1 = activeworkbook set pastestart = [file1.c5]  filetoopen = application.getopenfilename _ (title:="please choose xliff parse", _ filefilter:="report files *.xlf (*.xlf),")  if filetoopen = false     msgbox "no file specified.", vbexclamation, "error"     exit sub else     set wb2 = workbooks.open(filename:=filetoopen)      each sheet in wb2.sheets         sheet.usedrange             .copy pastestart             set pastestart = pastestart.offset(.rows.count)         end     next sheet  end if wb2.close range("c5:l3146").select     selection.delete shift:=xltoleft     range("d6:d2337").select     selection.delete shift:=xltoleft     range("e6:g2307").select     selection.delete shift:=xltoleft end sub 

set pastestart = activesheet.range("a1")  

should work.

also:

range("c5:l3146").select     selection.delete shift:=xltoleft     range("d6:d2337").select     selection.delete shift:=xltoleft     range("e6:g2307").select     selection.delete shift:=xltoleft 

should like:

with pastestart.parent     .range("c5:l3146").delete shift:=xltoleft     .range("d6:d2337").delete shift:=xltoleft     .range("e6:g2307").delete shift:=xltoleft end 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -