webquery and named range

Fredep57

New Member
Joined
Aug 3, 2005
Messages
8
OK, I have a stock VBA that I want to use to keep updated on my portfolio. However, each time I run the code, the named range gets a "_x" where x is some number.

Why???? I guess I don't fully understand what the code below does. Someone could help me understand better so I can get this working properly

CODE ========================

Sub GetDataNew(txtSymbol, qCount)
Dim ConnStr As String
Dim TargCell As String

ConnStr = "URL;http://finance.yahoo.com/q?s=" & txtSymbol & "&ql=1"
If Not qCount = 0 Then
TargCell = "A" & 11 * qCount
Else
TargCell = "A1"
End If
Worksheets("Sheet2").Activate
With ActiveSheet.QueryTables.Add(Connection:=ConnStr, Destination:=Range(TargCell))
.Name = txtSymbol
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertEntireRows
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = """table1"""
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub

Sub BuildNew2()
Dim txtSymbol As String
Dim txtFormula As String
Dim qCount As Integer
Dim fCell As String
' Uncomment (delete ') on line below if you'd rather not watch it working
' Application.ScreenUpdating = False

qCount = 0

Worksheets("Sheet3").Activate
Range("A3").Activate

Do While ActiveCell.Value <> ""
txtSymbol = ActiveCell.Value
Call GetDataNew(txtSymbol, qCount)
Worksheets("Sheet3").Activate
vCell = Worksheets("Sheet2").Range(txtSymbol).Cells(1, 2).Value
ActiveCell.Offset(0, 4).Value = vCell
ActiveCell.Offset(1, 0).Activate
qCount = qCount + 1
Loop

' Uncomment this if you uncommented the other code.
' Application.ScreenUpdating = True
End Sub

CODE ========================
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top