excel - VBA switching between workbooks gives wrong cell reference -



excel - VBA switching between workbooks gives wrong cell reference -

introduction:

i working on vba code imports info 1 sheet in workbook sheet in workbook. goal copy-paste-procedure re-create range a2 in targetworkbook a2 in sourceworkbook. procedure goes wrong.

code:

sub import() worksheets("alle borgere").range("a2:bz9999").clearcontents dim targetworkbook, sourceworkbook string dim startskurow, stopskurow integer dim cellvaluestring, rangetarget string dim quotebutton dim val(10) double on error resume next ' save workbook name , search old quote workbook sheet9.select ' quote sheet sourceworkbook = activeworkbook.name ' check workbook utilize old quote activewindow.activatenext targetworkbook = activeworkbook.name if targetworkbook = sourceworkbook msgbox ("Ă…ben venligst rette dokument") 'sheet9.protect 'exit sub end end if quotebutton = msgbox("er dette info til import?", vbyesnocancel) select case quotebutton case 2 ' cancel end case 6 ' yes exit case 7 ' no targetworkbook = "" case else end select loop until targetworkbook = sourceworkbook application.screenupdating = true startskurow = 0 stopskurow = 0 if quotebutton = 6 ' yes - start import sheet '!!the problem here!! workbooks(targetworkbook).activate sheets("alle borger").range("a2").select range(selection, activecell.specialcells(xllastcell)).select selection.copy activesheet.paste workbooks(sourceworkbook).activate sheet9.visible = xlsheetvisible sheet9.activate range("a2").select selection.pastespecial paste:=xlvalues, operation:=xlnone, skipblanks:= _ false, transpose:=false end if sheet1.activate application.screenupdating = true end sub

note !!the problem here, indiciates problem exist".

question: when code below executed selected area in targetworkbook detirmed not range("a2").select lastly click in targetworkbook.

workbooks(targetworkbook).activate sheets("alle borger").range("a2").select range(selection, activecell.specialcells(xllastcell)).select

why think case?

excel vba excel-vba

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -