Hi,
I have a macro that runs properly and does the following steps:
- Alows you to select the files you want
- Copy tha range "C30:K30" of every sheet called "Factura"
- Merge all the ranges in a new sheet.
I want to change it in order to get the same range ("C30:K30") but from the last sheet of every workbook. I think that is something like "Sheets(Sheets.Count).Select" but I can't integrate it in the correct way.
The macro is this:
Option Explicit
Sub GetData_Examplefactura()
Dim SaveDriveDir As String, MyPath As String
Dim FName As Variant, N As Long
Dim rnum As Long, destrange As Range
Dim sh As Worksheet
SaveDriveDir = CurDir
MyPath = Application.DefaultFilePath 'or use "C:\"
ChDrive MyPath
ChDir MyPath
FName = Application.GetOpenFilename(filefilter:="Excel Files,*.xl*", _
MultiSelect:=True)
If IsArray(FName) Then
' Sort the Array
FName = Array_Sort(FName)
Application.ScreenUpdating = False
'Add worksheet to the Activeworkbook and use the Date/Time as name
Set sh = ActiveWorkbook.Worksheets.Add
sh.Name = Format(Now, "dd-mmm-yyyy h-mm-ss")
'Loop through all files you select in the GetOpenFilename dialog
For N = LBound(FName) To UBound(FName)
'Find the last row with data
rnum = LastRow(sh)
'create the destination cell address
Set destrange = sh.Cells(rnum + 1, "A")
' For testing Copy the workbook name in Column E
sh.Cells(rnum + 1, "E").Value = FName(N)
'Get the cell values and copy it in the destrange
'Change the Sheet name and range as you like
GetData FName(N), "factura", "C30:K30", destrange, False, False
Next
End If
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub
Thank you so much in advance
I have a macro that runs properly and does the following steps:
- Alows you to select the files you want
- Copy tha range "C30:K30" of every sheet called "Factura"
- Merge all the ranges in a new sheet.
I want to change it in order to get the same range ("C30:K30") but from the last sheet of every workbook. I think that is something like "Sheets(Sheets.Count).Select" but I can't integrate it in the correct way.
The macro is this:
Option Explicit
Sub GetData_Examplefactura()
Dim SaveDriveDir As String, MyPath As String
Dim FName As Variant, N As Long
Dim rnum As Long, destrange As Range
Dim sh As Worksheet
SaveDriveDir = CurDir
MyPath = Application.DefaultFilePath 'or use "C:\"
ChDrive MyPath
ChDir MyPath
FName = Application.GetOpenFilename(filefilter:="Excel Files,*.xl*", _
MultiSelect:=True)
If IsArray(FName) Then
' Sort the Array
FName = Array_Sort(FName)
Application.ScreenUpdating = False
'Add worksheet to the Activeworkbook and use the Date/Time as name
Set sh = ActiveWorkbook.Worksheets.Add
sh.Name = Format(Now, "dd-mmm-yyyy h-mm-ss")
'Loop through all files you select in the GetOpenFilename dialog
For N = LBound(FName) To UBound(FName)
'Find the last row with data
rnum = LastRow(sh)
'create the destination cell address
Set destrange = sh.Cells(rnum + 1, "A")
' For testing Copy the workbook name in Column E
sh.Cells(rnum + 1, "E").Value = FName(N)
'Get the cell values and copy it in the destrange
'Change the Sheet name and range as you like
GetData FName(N), "factura", "C30:K30", destrange, False, False
Next
End If
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub
Thank you so much in advance