excel - Copy data from one workbook to the other workbook sheet -


i new vba excel. trying copy data on worksheet workbook other worksheet on workbook. user choose file want open through file dialog. however, keep error of runtime error 9: subscript out of range. can please enlighten me. thank you.

sub selectfile() dim filetoopen string dim wb2 workbook dim wb1 workbook dim sheet worksheet application.screenupdating = false sheet2.range("a:y").clearcontents filetoopen = application.getopenfilename _ (title:="please choose excel file open", _ filefilter:="excel files *.xlsx(*.xlsx),") sheet1.range("b30").value = filetoopen set wb2 = workbooks.open(filetoopen) set sheet = wb2.worksheets(1) wb2.activate sheet.copy after:=workbooks("oqc_check_tools.xlsm").sheets("sheet2")  end sub 

sub selectfile() dim filetoopen string dim wb2 workbook dim wb1 workbook dim sheet worksheet application.screenupdating = false sheet2.range("a:y").clearcontents filetoopen = application.getopenfilename _ (title:="please choose excel file open", _ filefilter:="excel files *.xlsx(*.xlsx),") sheet1.range("b30").value = filetoopen set wb2 = workbooks.open(filetoopen) set sheet = wb2.worksheets(1) sheet.usedrange.copy destination:=thisworkbook.worksheets(2).range("a1")  end sub 

try code.


Comments

Popular posts from this blog

'hasOwnProperty' in javascript -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

How to understand 2 main() functions after using uftrace to profile the C++ program? -