Need advice: Need to pick up filename, pick up info and into a mastercopy.

Shinn94

New Member
Joined
Jul 20, 2017
Messages
7
Hi all:

My apologies if this has been asked before in the forum, I could not find anything similar to what I need help on.

So I am looking for a set of VBA code to loop through every xls files in the folder and pick up it's file name, who it is prepared by, authorised by and management checked by. Into a mastercopy.

The problems so far are:

The folder path (C:\local folder\local directory\month\type\entity) - I could set the file path up to type but I would need to have the entity interchangeable according to what I've got in a list on EXCEL, so some sort of blanket cover covering every entity and its xls files inside.

The file name, I don't know the code to pick up each file name accordingly and pick up the name of the person who prepared it. (kind of like a vlookup that will return the file name, prepared by person's name, authorised by person's name and management checked by name)

Here is the code I've managed so far - (I have just copy and paste from places on the internet and cater according to my needs):

Sub REC()
Dim WBname As String 'Deem WBname as variable
Dim WB As Workbook 'Deem WB as workbook
Dim WS As Worksheet 'Deem WS as worksheet
Dim WS1 As Worksheet
Dim lngCalc As Long
Dim lngrow As Long
Dim Preparedby As Range
With Application
.ScreenUpdating = False
.EnableEvents = False
lngCalc = .CalculationState
.Calculation = xlCalculationManual
End With
Set WS1 = ThisWorkbook.Sheets("Sheet1")
FolderName = "Local path" 'set the folder path
WBname = Dir(FolderName & "" & "*.xls*") 'filename wildcard
Do While Len(WBname) > 0
Set WB = Workbooks.Open(FolderName & "" & WBname) 'open specified path and file
Set WS = Nothing 'if ws is nothing then move on
On Error Resume Next 'next line if error
Set WS = WB.Sheets("rec cert") 'pick up sheet rec cert, but it is not the only variation
On Error Resume Next
Set WS = WB.Sheets("a1 rec cert") 'pick up sheet a1 rec cert, but it is not the only variation
On Error GoTo 0
If Not WS Is Nothing Then

With WS
Set Preparedby = WS.Range("A:D").Find("prepared by", LookIn:=xlValues, LookAt:=xlWhole) 'find "prepared by" in range A:D
On Error Resume Next
Set Preparedby = Nothing
End With
With WS
Set Preparedby = WS.Range("A:D").Find("prepared by", LookIn:=xlValues, LookAt:=xlWhole)
If Not Preparedby Is Nothing Then 'if true, next line
Preparedby.Activate
ActiveCell.Offset(0, 1).Copy 'meant to pick up the name that is offset by column 1 and copy
End If
End With

With WS1
ThisWorkbook.Activate 'activate this work book
If Not ActiveCell Is Nothing Then
ActiveCell.Offset(1, 0).PasteSpecial 'destination
End If
End With

End If
WB.Close False
WBname = Dir
Loop
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = lngCalc
End With
End Sub


Perhaps anyone could advice me? I am only a beginner at VBA coding.

Many thanks in advance.
Shinn
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,216,151
Messages
6,129,162
Members
449,489
Latest member
spvclub

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