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