Hello everybody,
I'm trying to export data and filtered them from a file selected by an user before copying and pasting it in one file. I want to :
- Filtered the data on columns F and H
- Then copy the data from B to L columns without the headers
I added an image of the type of data I want to export.
There are others things I want to do but I'm focusing on those two aspect at the moment
So far with what I found and understood on the internet I manage to do this :
I get an error while running it
Sub Test2()
Dim Fname As String
Dim SrcWbk As Workbook
Dim DestWbk As Workbook
Set DestWbk = ThisWorkbook
Fname = Application.GetOpenFilename(FileFilter:="Macro Files (*.xlsm*), *.xlsm*", Title:="Select a File")
If Fname = "False" Then Exit Sub
Set SrcWbk = Workbooks.Open(Fname)
With SrcWbk.Range("A1:AI1")
.autofilter Field:=6, Criteria1:="Bloqué"
.autofilter Field:=8, Criteria1:="JEB"
End With
SrcWbk.Sheets("Base").Range("B:AI").Copy DestWbk.Sheets("Sheet1").Range("A1")
SrcWbk.Close False
End Sub
I'm an newbie in VBA, I'm a bit lost right now and don't know where to go.
Thanks you for any help provide
I'm trying to export data and filtered them from a file selected by an user before copying and pasting it in one file. I want to :
- Filtered the data on columns F and H
- Then copy the data from B to L columns without the headers
I added an image of the type of data I want to export.
There are others things I want to do but I'm focusing on those two aspect at the moment
So far with what I found and understood on the internet I manage to do this :
I get an error while running it
Sub Test2()
Dim Fname As String
Dim SrcWbk As Workbook
Dim DestWbk As Workbook
Set DestWbk = ThisWorkbook
Fname = Application.GetOpenFilename(FileFilter:="Macro Files (*.xlsm*), *.xlsm*", Title:="Select a File")
If Fname = "False" Then Exit Sub
Set SrcWbk = Workbooks.Open(Fname)
With SrcWbk.Range("A1:AI1")
.autofilter Field:=6, Criteria1:="Bloqué"
.autofilter Field:=8, Criteria1:="JEB"
End With
SrcWbk.Sheets("Base").Range("B:AI").Copy DestWbk.Sheets("Sheet1").Range("A1")
SrcWbk.Close False
End Sub
I'm an newbie in VBA, I'm a bit lost right now and don't know where to go.
Thanks you for any help provide