Hi All,
I am trying to run a macro to pull data from a Workbook using an SQL command. I have 10 different cells in which I want to paste the resulting data (there are in a row, so all different columns), the values which they are pulling are based on the Offset I have put in which relates to either 4 or 3 cells above it.
Here is the code:
I have tried everything and keep getting the error 'Object variable or With variable not set'
Does anyone have any suggestions.
I am trying to run a macro to pull data from a Workbook using an SQL command. I have 10 different cells in which I want to paste the resulting data (there are in a row, so all different columns), the values which they are pulling are based on the Offset I have put in which relates to either 4 or 3 cells above it.
Here is the code:
Code:
Private Sub LW17464()
Dim rngOutput As Range
Dim strSQL As String
Dim strFile As String
Dim Cel As Range
Dim CelLow As Integer
Dim CelHigh As Integer
Cel = Range("_LW17464")
For Each Cel In Range("_LW17464")
CelLow = Cel.Offset(-4, 0)
CelHigh = Cel.Offset(-3, 0)
strFile = "E:\MES_WIPBoards\MESAllParts.xlsm"
Set rngOutput = Cel
strSQL = "SELECT [Order ID] FROM lw17464ids WHERE [Current OP]>(CelLow) AND [Current OP]<=(CelHigh)"
'strSQL = "SELECT DISTINCT [Part No] FROM output_Table_2;"
Call PasteFromSQL(strSQL, strFile, rngOutput)
Next
End Sub
I have tried everything and keep getting the error 'Object variable or With variable not set'
Does anyone have any suggestions.