excel - VBA: copy paste from selected workbooks based on cell value -
i want copy data selected different workbooks based on cell value , paste 1 single workbook
enter code here sub ram_copypaste() dim w workbook dim string dim x worksheet dim j integer dim integer j = cells(2, 1).value = "portfolio" b = ".xlsx" = 1 j set w = & & b set x = & w.worksheets("download1").range("a1:h14").copy workbooks("te copypaste.xlsx").x.cells(1, 1).pastespecial xlpastevalues next end sub
try this: use debug.print @ various points understand code better.
sub ram_copypaste() dim w workbook dim string, b string dim x worksheet dim j integer dim integer j = cells(2, 1).value 'use debug.print check value of j = "portfolio" b = ".xlsx" = 1 j set w = workbooks(a & & b) 'make sure have workbook 'with same name & & b opened otherwise give error. if 'you don't have opened have on drive first open , set it. set x = w.sheets(a & i) 'as suggested anil kumar avoid type mismatch error w.worksheets("download1").range("a1:h14").copy workbooks("te copypaste.xlsx").x.cells(1, 1).select workbooks("te copypaste.xlsx").x.cells(1, 1).pastespecial xlpastevalues application.cutcopymode = false next end sub
Comments
Post a Comment