VBA Script to pull certain cells from Marco enable workbook

hiteshvarsani

New Member
Joined
Jul 26, 2022
Messages
1
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi,

We have around 300 macro enabled workbooks that are all in the same format and all have the same cells.

I would like to know the best way to extract all the answers from the Questionnaire and put them in a table in a master excel file.

I have tried the below but can only get a few cells as tables, to make things more interesting some of the spreadsheets have multiple tabs or each application, so again all in the same format:

Private Const sPath As String = "C:\Users\" 'CHANGE THIS TO YOUR DIRECTORY PATH

Sub LoopThroughFiles()

Dim sFile As String 'File Name
Dim sExt As String 'File extension you wish to open

sExt = "xlsm" 'Change this if extension is different

'loop through each file name and open it if the extension is correct
sFile = Dir(sPath)
Do Until sFile = ""
If Right(sFile, 4) = sExt Then GetInfo sFile
sFile = Dir
Loop


End Sub

Private Sub GetInfo(sFile As String)

Dim wbFrom As Workbook 'workbook to copy the data from
Dim iRow As Integer 'row number of next empty row

On Error GoTo errHandle

Application.EnableEvents = False
Application.ScreenUpdating = False

Set wbFrom = Workbooks.Open(sPath & sFile)


wbFrom.Sheets("App Item (1)").Range("C4:C10").Copy 'Copy A1:A10
iRow = Me.Range("A" & Rows.Count).End(xlUp).Row + 1 'Get an empty row in this workbook
Me.Range("A" & iRow).PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True 'paste copied cells
wbFrom.Close (False)

Application.EnableEvents = True
Application.ScreenUpdating = True
Set wbFrom = Nothing

Exit Sub
errHandle:
MsgBox Err.Description
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

any help would be much appreciated.

Thanks

Hitesh
 

Attachments

  • BFA.JPG
    BFA.JPG
    240.1 KB · Views: 9

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top