VBA Exercise-call data from two libraries into the active table

Source: Internet
Author: User

Practice VBA

Subwarehousing ()DimBasedb as String, cpdb as String, WB asWorkbook, WS asWorksheet, Curws asWorksheet basedb= Thisworkbook.path &"\ Analyze data. xlsx"cpdb= Thisworkbook.path &"\ Product sampling information. xlsx"        'extracting in the Analysis database    If Len(Dir(Basedb)) =0  Then        MsgBox "file not found:"& VbCrLf & Basedb, vbexclamation,"Error"    Else        SetWB =GetObject(basedb)SetCURWS =ActiveSheet'the number of rows in the current active tableCurlastrow = Curws.range ("d6556"). End (Xlup). Row fori =4  toCurlastrow'Product Lot numberv = Range ("D"&i) for  eachWsinchWB. Worksheets'number of rows in the analysis libraryWslastrow = ws. Range ("a65536"). End (Xlup). Row forj =4  toWslastrowIfWs. Range ("a"& j) = V ThenCurws.range ("O"& I &": U"& i) = ws. Range ("C"& J &": I"&j). Value Curws.range ("X"& i) = ws. Range ("N"&j) Curws.range ("G"& i) = Range ("X"& i) & Range ("Y"&i)Exit  for                    End If                Next            Next        NextWB. CloseEnd If        'extraction of finished product sampling information      If Len(Dir(cpdb)) =0  Then        MsgBox "file not found:"& VbCrLf & cpdb, vbexclamation,"Error"    Else        SetWB =GetObject(cpdb)SetCURWS =ActiveSheet Curlastrow= Curws.range ("d6556"). End (Xlup). Row fori =4  toCurlastrow v= Range ("D"&i) for  eachWsinchWB. Worksheets Wslastrow= ws. Range ("a65536"). End (Xlup). Row forj =3  toWslastrowIfWs. Range ("a"& j) = V ThenCurws.range ("V"& i) = ws. Range ("Q"&j)Exit  for                    End If                Next            Next        NextWB. CloseEnd If        'Close Tool LibraryWindows ("Tool Library. XLSM"). Activate Activewindow.closeFalse       End Sub

VBA Exercise-call data from two libraries into the active table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.