vba - Using SQL to copy data from worksheets to other worksheets in the same workbook? -


i use sql move data around sheet sheet within same workbook.

my sheets large (width & depth) , coping vba slow.

the scenario have sheets 1 5.
want create sheet(6) column or 2 sheets 1 -5.
index key sku , common sheets. sheets sorted sku begin with.

when grab column in sheet(1) can put in sheet(6), column a. when grab column in sheet(2) need sure each row's sku matches , data sheet(2) , correctly placed in next column sku. if data sku not available corresponding cell left empty. data each column kept in 1 selected column in target worksheet.

i not how set connection or recordset selections since working within same workbook. cannot find topic discussed anywhere. ensuring sku receives correct data sheets seems little daunting me.

i seem remember not being able establish ado connections open workbooks/sheets. if case create separate workbook extract data , manipulate there.

i appreciate guidance on subject. new ground me.

thanks, craigm

below solution created:
got sheet1, sheet2 described below images:
sheet1 sheet2
copy using sql, following code been used:
note: need go tools > reference > check microsoft activex data objects 2.8 library , microsoft forms 2.0 object library

sub sqlcopy()   dim myconnection adodb.connection dim myrecord adodb.recordset  set myconnection = new adodb.connection set myrecord = new adodb.recordset  ' excel 97-2003 connection string. should work ' excel 2007 onwards worksheets long have less 65536 ' rows myconnection     .provider = "microsoft.jet.oledb.4.0"     .connectionstring = "data source=" & thisworkbook.fullname & ";" & _         "extended properties=excel 8.0;"     .open end  myrecord.open "select [sheet1$].[sku],[seconddata] [sheet1$],[sheet2$] " & _     "[sheet1$].[sku]  = " & _     "[sheet2$].[sku]", myconnection  sheets("sheet3").cells(2, 1).copyfromrecordset myrecord  myrecord.close myconnection.close  end sub 


following result @ sheet 3
sheet3


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -