Hi,
Its been a while since I've had to use this forum, I wish I could say it was good to be back haha. Stuck on making a loop for a spreadsheet I'm working on.
In a nutshell, I have a list of several ticker symbols. I'm trying to grab the dividend history for each ticker symbol for a specific range. The formula I'm attaching succeeds for the first item on the list. I have to figure out how to make it into a loop that adds the dividend history for the other ticker symbols below columns I-O. The kicker is for the Bloomberg data to refresh, you must exit the subroutine. I think I need to store a named range in the sheet somewhere to be my "i" variable or loop counter. But I'm not very good at that sort of thing and after playing around for a while, I'm stuck. Any help would be much appreciated. I'm attaching the workbook. But the code is this (I realize cell references to I3, M3, etc. might need to be changed):
Sub DivLoop()
' Dividend Loop
'----------------------------------------------------------------------------------------------------------------------------
'Macro designed to format spreadsheet for all dividends over a certain time frame.
'------------------------------------------------------------------------------------------
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Range("I3").Value = "=BDS(RC[-7],""DVD_HIST_ALL"",""DVD_START_DT"",R[-2]C[-6],""DVD_END_DT"",R[-2]C[-3],)"
'Code to somehow refresh the excel sheet
Application.Run "bloombergui.xla!RefreshEntireWorkbook"
Call checkIfDone
End Sub
Sub ProcessDivData()
If Range("M3") <> "" Then
Range("H3").Value = "=F3*M3"
End If
If Range("M4") <> "" Then
Range("H4").Value = "=F4*M4"
End If
End Sub
Sub checkIfDone()
If Sheets("S&P 500").Range("A1").Value <> 0 Then
Application.OnTime Now + TimeValue("00:00:01"), "checkIfDone"
Else
ProcessDivData
End If
End Sub
Bookmarks