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 ========================
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 ========================