I have a piece of code:
This basically refreshes a table in the data warehouse. Then copies data and pastes it into a separate tab.
At the moment this query gets repeated about 20 times.
Is there anyway to make it so the query runs if a number is greater than a cell value.
For example: I have the number 5 written in cell A1 on one of the tabs ("Sheet1")
If the above code was given 'PieceOfCode' number 4, it would run the macro code (because 4 is less than 5).
However if the above code was given 'PieceOfCode' number 6, it would NOT run the macro code (because 6 is greater than 5)
Hope that makes sense.
Any help, would be appreciated.
Code:
Windows(MyWorkbook).Activate Sheets("List").Select
Range("A1").Select
Dim Code1a As Excel.Range, Code1b As Excel.Range, Code1c As Excel.Range
Dim Code2a As Excel.Range, Code2b As Excel.Range, Code2c As Excel.Range
Dim Code3a As Excel.Range, Code3b As Excel.Range, Code3c As Excel.Range
Set Code1a = Range("U2")
Set Code1b = Range("V2")
Set Code1c = Range("W2")
Set Code2a = Range("U3")
Set Code2b = Range("V3")
Set Code2c = Range("W3")
Set Code3a = Range("U4")
Set Code3b = Range("V4")
Set Code3c = Range("W4")
Windows(JointWorkbook).Activate
Sheets("P1T1").Select
Range("A1").Select
With Selection.ListObject.QueryTable
.Connection = _
"ODBC;DRIVER=SQL Server;SERVER=DW-SQL;UID=gbell;Trusted_Connection=Yes;APP=Microsoft Office 2010;WSID=SOUR-00093-L;DATABASE=RDW"
.CommandText = Array( _
"SELECT view_Billing_v4.BillingDoc, view_Billing_v4.BillToCountry, view_Billing_v4.BillingDate, view_Billing_v4.ShipToCountry, view_Billing_v4.SalesDoc, view_Billing_v4.SalesDistrictText, view_Billing_" _
, _
"v4.ProductNo, view_Billing_v4.ProductText, view_Billing_v4.BillingQty, view_Billing_v4.ProductHierarchy, view_Billing_v4.USD_NetSales1, view_Billing_v4.USD_Cost, view_Billing_v4.BillMonth, view_Billin" _
, _
"g_v4.BillQuarter, view_Billing_v4.BillYear, view_Billing_v4.ProductHierarchyText_Material, view_Billing_v4.ItemCategoryCode" & Chr(13) & "" & Chr(10) & "FROM RDW.dm.view_Billing_v4 v" _
, _
"iew_Billing_v4" & Chr(13) & "" & Chr(10) & "WHERE (" & Code1a & ")" _
, _
" AND (" & Code1b & ")" _
, _
" AND (" & Code1c & ")" _
, _
" OR (" & Code2a & ")" _
, _
" AND (" & Code2b & ")" _
, _
" AND (" & Code2c & ")" _
, _
" OR (" & Code3a & ")" _
, _
" AND (" & Code3b & ")" _
, _
" AND (" & Code3c & ")" _
)
.Refresh BackgroundQuery:=False
End With
Range("A1").Select
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
Range("Table_view_Billings_V4[[#Headers],[BillingDate]]").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("P1T2").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("A1").Select
This basically refreshes a table in the data warehouse. Then copies data and pastes it into a separate tab.
At the moment this query gets repeated about 20 times.
Is there anyway to make it so the query runs if a number is greater than a cell value.
For example: I have the number 5 written in cell A1 on one of the tabs ("Sheet1")
If the above code was given 'PieceOfCode' number 4, it would run the macro code (because 4 is less than 5).
However if the above code was given 'PieceOfCode' number 6, it would NOT run the macro code (because 6 is greater than 5)
Hope that makes sense.
Any help, would be appreciated.