Locate excel file, then extract columns, paste special values into a named sheet / tab

Pup Denab

Active Member
Joined
May 12, 2013
Messages
299
HI Everyone
I hope one of you can help me with this,
I need to copy columns A-P, then paste special (values only) into another sheet, my problem is the sheet where its going is named however the sheet where it comes from is a system generated name, which is alpha numeric (and not open), the only constant is where it is saved, as this is automatic extracted, into a certain folder, is it possible to collect the data from the newest excel sheet in a folder ?


From
C:\Documents and Settings\All Users\Desktop\updatenov\anyname

To
C:\Documents and Settings\All Users\Desktop\matrix.xlsm\rawdata

I'm looking for vba solution to automate the process

any help would be welcome
Thanks
 
Sorry I forgot to include current code that I am trying to piece together without luck:
Code:
Sub AllFiles()Dim MyFolder As String 'Path containing the files for looping
Dim MyFile As String 'Filename obtained by Dir function
Dim MyBook As Workbook
MyFolder = "C:\Desktop\XXXAccount Master" & Application.PathSeparator 'Assigndirectory to MyFolder
MyFile = Dir(MyFolder & "*.xlsx") 'Dir gets the first file of the folder
If MyFile = "" Then
MsgBox "No files found in " & MyFolder & " with extension .xlsx"
Exit Sub
End If
Do
Call PupDenab
Loop
End Sub
Sub PupDenab()
Const destWb As String = "wbtest.xlsm" 'Change to suit
Dim pStr As String, MyFile As String, LastSav As Variant, fNam As String
pStr = "C:\Desktop\XXXAccount Master\"
MyFile = Dir(pStr & "*.xlsx")
If MyFile = vbNullString Then
Exit Sub
Else
LastSav = FileDateTime(pStr & MyFile)
fNam = MyFile
End If
Do
MyFile = Dir()
If MyFile = vbNullString Then Exit Do 'No files left in folder
If FileDateTime(pStr & MyFile) > LastSav Then
LastSav = FileDateTime(pStr & MyFile)
fNam = MyFile
End If
Loop
If Not WorkBookOpen(fNam) Then
Workbooks.Open pStr & fNam
End If
Workbooks(fNam).Sheets("Sheet1").Columns("A:P").Copy
Workbooks(destWb).Sheets("shtest").Range("A1").PasteSpecial Paste:=xlValues
Workbooks(fNam).Sheets("Sheet1").Range("B2").Select
Application.CutCopyMode = False
ActiveWindow.Close
End Sub


Function WorkBookOpen(book As String)
Dim wbName As String
On Error GoTo notOpen
wbName = Workbooks(book).Name
WorkBookOpen = True
Exit Function
notOpen:
WorkBookOpen = False
End Function
 
Last edited:
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,223,725
Messages
6,174,134
Members
452,546
Latest member
Rafafa

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