Thursday 15 April 2010

vba - Copy data from multiple excel sheets and append that to a single excel sheet using VBScript -



vba - Copy data from multiple excel sheets and append that to a single excel sheet using VBScript -

the scenario follows:

i have excel (.xls) file data. (eg. a.xls) the info on excel file on single worksheet (sheet 1). the number of columns in file fixed i.e. 8 however, number of rows containing info may vary time time. (this file updated programme time time) now, have excel file (eg. b.xls) similar type of info not same contents of a.xls. the number of columns in b.xls 8 well. however, number of rows containing info unknown.

i want re-create contents of a.xls, 2nd row onwards (excluding 1st row containing column headers) , append/paste same b.xls file, without over-writing existing info on b.xls.

with these details in mind, want write vbscript automate task.

please help.

thanks lot, in advance.

it needs lot of cleanup, should work. i'll clean bit , create edit.

sub copyrows() ' take name of sec workbook , lastly column. ' must in same directory first workbook. secondworkbook = "b.xls" lastcolumn = "h" ' couple more variables currentworkbook = thisworkbook.name workbooks.open thisworkbook.path & "\" & secondworkbook ' in first workbook, find , select first empty ' cell in column on first worksheet. windows(currentworkbook).activate worksheets(1).columns("a:a") set c = .find("", lookin:=xlvalues) if not c nil ' select , re-create a2 end. secondaddress = replace(c.address, "$a$", "") range("a2:" & lastcolumn & cstr(cint(secondaddress) - 1)).select selection.copy end if end ' activate sec workbook windows(secondworkbook).activate worksheets(1).columns("a:a") set c = .find("", lookin:=xlvalues) if not c nil ' select , paste info first workbook range(c.address).select activesheet.paste end if end end sub

update: should trick. copied wrong workbook first time around, too. allow me know if have questions.

excel vba excel-vba vbscript

No comments:

Post a Comment