I am running into a problem with the following code, specifically when hitting run I am getting the error message "Run Time Error 91 : Object Variable or With Block Variable Not Set".
I have attached a picture of what line is highlighted in yellow. Thanks
VBA Code, run time error object
Sub Data_Get()
Dim ActiveSheet As Worksheet
Dim EndDate As Date
Dim StartDate As Date
Dim Symbol As String
Dim qurl As String
Dim nQuery As Name
Dim LastRow As Integer
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
Columns("B:G").ClearContents
StartDate = Range("K2").Value
EndDate = Range("K3").Value
Symbol = Range("K1").Value
qurl = "http://finance.google.com/finance/historical?q=" & Symbol
qurl = qurl & "&startdate=" & MonthName(Month(StartDate), True) & _
"+" & Day(StartDate) & "+" & Year(StartDate) & _
"&enddate=" & MonthName(Month(EndDate), True) & _
"+" & Day(EndDate) & "+" & Year(EndDate) & "&output=csv"
QueryQuote:
With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=Range("b1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
End With
Range("B1").CurrentRegion.TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False, other:=False
Columns("B:G").ColumnWidth = 12
LastRow = ActiveSheet.UsedRange.Row - 2 + ActiveSheet.UsedRange.Rows.Count
ActiveSheet.Sort.SortFields.Add Key:=Range("B2:B" & LastRow), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveSheet.Sort
.SetRange Range("B1:G" & LastRow)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
.SortFields.Clear
End With
End Sub