So I have an issue, I created a loop to find where the sheet says "Standard Deviation" and for it to pull the data 3 cells to the right of it. The issue is this is supposed to pull data after the Query Table loads. My code won't work because it runs before the Querytable loads.
Sub StdB5()
Dim URL As String
Dim ws As Worksheet
Dim qt As QueryTable
Dim mep As Worksheet
Dim Symbol As String
Set mep = Worksheets("Managed Equity Portfolios")
Set ws = Worksheets("Hidden Sheet 3")
Sheets("Hidden Sheet 3").Cells.ClearContents
Sheets("Hidden Sheet 3").Visible = True
Symbol = Symbol & mep.Range("B5").Value
URL = "https://www.google.com/finance?q=MUTF:" + Symbol
Set qt = ws.QueryTables.Add( _
Connection:="URL;" & URL, _
Destination:=ws.Range("A1"))
qt.Refresh
Dim stdRange As Range
Dim cel As Range
Dim stdcell As Range 'std on MEP
Set stdcell = mep.Cells.Range("H5") 'std on MEP
Set stdRange = ws.Range("A45:A50")
For Each cel In stdRange
If cel.Value = ("Standard deviation") Then
stdcell.Value = cel.Offset(0, 3).Value
End If
Next cel
Is there any way to make it so it waits until the Query Table loads before running? Instead of having to physically run the macro again after the table loads?
Edit: The reason I need to do this is because sometimes after the QT runs, the standard deviation will be in, for example, cell A45 instead of A47. This makes it so I can't just make the cell I want to populate ='Sheet2'A45' Edit 2: Added whole code