• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member
  • Login

Macro to open multiple files and extracts data from them |VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Macro to open multiple files and extracts data from them |VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosMacro to open multiple files and ex…
sp_PrintTopic sp_TopicIcon
Macro to open multiple files and extracts data from them
Avatar
Paula Andrea Ordoñez

New Member
Members
Level 0
Forum Posts: 1
Member Since:
April 30, 2020
sp_UserOfflineSmall Offline
1
April 30, 2020 - 11:09 pm
sp_Permalink sp_Print sp_EditHistory

Hi to all of you, I  am working in a project in VBA and I am trying to add some information to the following code and I am a little confuse, maybe someone can help:

1. I would like to add a column (in column A) calls "Laboratory" that extracts the information of cell P2 of the "report stampabile"

2. To add a column (in column B) calls "Evaluation Date" that extracts the infomation of cell I3 from "report stampabile"

3. To add a column (in column C) calls "Technical Functionary" that extract the informationof cell E18 from "Rilievo 1"

4. To add a column (in column F) calls "Inspector 2" that extract the information of d14,d24,d34 etc from "report stampabile"

files attached are the ones that have to be used to be opened and extract the data

 

This is the code I have: 

  1. Sub Consolidate_Data()
  2. Application.ScreenUpdating = False
  3. Dim wb As Workbook, sh As Worksheet, dsh As Worksheet, File_Name As Variant, i As Long, lr As Long, x As Long
  4. Dim desWS As Worksheet, srcWS As Worksheet, r As Long: r = 6
  5. Set dsh = ThisWorkbook.Sheets("Sheet1")
  6. dsh.UsedRange.ClearContents
  7. File_Name = Application.GetOpenFilename("Excel Files (*.xl*),*.xl*", , "Select Excel Files To Consolidate", , True)
  8. For i = LBound(File_Name) To UBound(File_Name)
  9. Set wb = Workbooks.Open(File_Name(i))
  10. If Not Evaluate("isref('" & "ExtractedData" & "'!A1)") Then
  11. Sheets.Add before:=Sheets(1)
  12. ActiveSheet.Name = "ExtractedData"
  13. Range("A1").Resize(, 5) = Array("Classification", "Inspector", "Standard", "Requirement", "Classification Rilievi")
  14. Columns.AutoFit
  15. Else
  16. Sheets("ExtractedData").UsedRange.Offset(1).ClearContents
  17. End If
  18. Set desWS = Sheets("ExtractedData")
  19. Set srcWS = Sheets("report stampabile")
  20. lr = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
  21. For x = 5 To lr Step 10
  22. Select Case srcWS.Range("P" & x).Value
  23. Case "NC", "OSS", "COM"
  24. With desWS
  25. .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Resize(, 4).Value = Array(srcWS.Range("P" & x), srcWS.Range("P" & x).Offset(6, -12), srcWS.Range("P" & x).Offset(1, -13), srcWS.Range("P" & x).Offset(1, -9))
  26. With Sheets(r)
  27. Select Case .Range("P5").Value
  28. Case "OSS", "NC", "COM"
  29. desWS.Cells(desWS.Rows.Count, "E").End(xlUp).Offset(1) = Sheets(r).Range("P5")
  30. r = r + 1
  31. If desWS.Cells(desWS.Rows.Count, "E").End(xlUp) = 0 Then
  32. desWS.Cells(desWS.Rows.Count, "E").End(xlUp) = ""
  33. End If
  34. End Select
  35. End With
  36. End With
  37. End Select
  38. Next x
  39. With desWS
  40. .Columns.AutoFit
  41. .UsedRange.Copy dsh.Cells(dsh.Rows.Count, "A").End(xlUp).Offset(1)
  42. End With
  43. wb.Close False
  44. r = 6
  45. Next i
  46. With dsh
  47. .Rows(1).Delete
  48. .Columns.AutoFit
  49. End With
  50. Application.ScreenUpdating = True
  51. End Sub
Avatar
Purfleet
England
Member
Members


Trusted Members
Level 4
Forum Posts: 414
Member Since:
December 20, 2019
sp_UserOfflineSmall Offline
2
May 1, 2020 - 5:00 am
sp_Permalink sp_Print

Can you please add a sample workbook so we dont have to recreate all the data

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: QSolutions Group
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 880
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 237
Jessica Stewart: 219
A.Maurizio: 213
Aye Mu: 201
Hans Hallebeek: 185
Newest Members:
Kate Dyka
Kwaje Alfred Mogga
thong nguyen
Appiagyei Kofi Frimpong
Hilary Burchfield
Richie Wright
Adel Kock
Barbara Murray
Doug Milne
Siobhan Stringer
Forum Stats:
Groups: 3
Forums: 24
Topics: 6547
Posts: 28656

 

Member Stats:
Guest Posters: 49
Members: 32832
Moderators: 2
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel Office Scripts
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook

Sign up to our newsletter and join over 400,000
others who learn Excel and Power BI with us.

 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate
  • Sponsor Our Newsletter

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.