APCaldwell
New Member
- Joined
- Dec 9, 2017
- Messages
- 2
Hi, my name is Andrew and I am new to this forum, hope I do everything correctly,
I have a macro that extracts data from Access. before the data lands in the excel worksheet, I want to filter the data by a variable that is defined in a cell reference.
I have tried to use a dim option but I receive an error informing me that the variable text is unknown.
Please note my code, I have highlighted the variable in red, please can you assist me with what I am doing wrong?
Sheets("Transactions").Select
Dim mybrand As Range
Range("U1").Select
ActiveSheet.Calculate
Set mybrand = Range("U1")
Sheets("Metabase_Transactions").Select
ActiveWorkbook.Queries.Add Name:="Transactions_File", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Access.Database(File.Contents(""C:\MODZ\Kalbe\Meta_Base_Master\Meta_Base_Master v1.accdb""), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Transactions_File = Source{[Schema="""",Item=""Transactions_File""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Filtered Rows"" = Table.SelectRows(_Transactions_File, each ([Mas_Brand] =mybrand))" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filtered Rows"""
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Transactions_File;Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [Transactions_File]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Transactions_File"
.Refresh BackgroundQuery:=False
End With
Hope you can help and again, please forgive me if I have said or done something wrong in this posting.
I have a macro that extracts data from Access. before the data lands in the excel worksheet, I want to filter the data by a variable that is defined in a cell reference.
I have tried to use a dim option but I receive an error informing me that the variable text is unknown.
Please note my code, I have highlighted the variable in red, please can you assist me with what I am doing wrong?
Sheets("Transactions").Select
Dim mybrand As Range
Range("U1").Select
ActiveSheet.Calculate
Set mybrand = Range("U1")
Sheets("Metabase_Transactions").Select
ActiveWorkbook.Queries.Add Name:="Transactions_File", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Access.Database(File.Contents(""C:\MODZ\Kalbe\Meta_Base_Master\Meta_Base_Master v1.accdb""), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Transactions_File = Source{[Schema="""",Item=""Transactions_File""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Filtered Rows"" = Table.SelectRows(_Transactions_File, each ([Mas_Brand] =mybrand))" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filtered Rows"""
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Transactions_File;Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [Transactions_File]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Transactions_File"
.Refresh BackgroundQuery:=False
End With
Hope you can help and again, please forgive me if I have said or done something wrong in this posting.