Hi dotsofcolour
My approach would be to keep a calling macro in a separate file, then use it to select the file you want to work with and process things that way.
Here is some code that should do the trick. Please note there is no error handling, so if the sheet format is not exact then trouble is brewing!
Run the StartHere macro, it will call the others as required.
Sub StartHere()
Dim sfile As String
Dim iAgain As Integer
Rerun:
sfile = GetFile
MsgBox sfile
Call FormatFile(sfile)
iAgain = MsgBox("Do you want to get another file?", vbYesNo, "RUN AGAIN???")
If iAnswer = vbYes Then GoTo Rerun
End Sub
Function GetFile() As String
Dim iRep As Integer
Dim vFileToOpen As Variant
Do Until iRep = vbYes
MsgBox "Explorer will now open - Choose the file you want to get data from"
vFileToOpen = Application.GetOpenFilename(FileFilter:="Excel Files (*.xlsx), *.xlsx,Excel Files (*.xls), *.xls", Title:="Please select a file")
If vFileToOpen = False Then
End ' They pressed Cancel
Else
iRep = MsgBox("ARE YOU SURE " & vFileToOpen & " IS THE CORRECT FILE ???", vbYesNo, "GET SOURCE FILE!")
End If
Loop
GetFile = vFileToOpen
End Function
Sub FormatFile(sfile As String)
Dim wbS As Workbook
Dim wsS As Worksheet
Dim lLR As Long
Dim rng As Range
Set wbS = Workbooks.Open(sfile, local:=True)
For Each wsS In wbS.Sheets
With wsS
'find last row in data block
lLR = .Range("A" & .Rows.Count).End(xlUp).Row
Set rng = .Range("a4:g" & lLR)
'sort by balance which is row 1, column 4 of the 'rng' block
rng.Sort Key1:=rng(1, 4), Order1:=xlDescending, Header:=xlYes
'format to currency
Set rng = .Range("d5:g" & lLR)
rng.NumberFormat = "$#,##0.00"
End With
Next wsS
wbS.Close
Set rng = Nothing
Set wsS = Nothing
Set wbS = Nothing
End Sub
Hope this solves, or points you in the right direction
Regards
Bookmarks