Hi,
I am using a Bloomberg function that gives its output on 2 lines (rows). The function is looping over a large number of cells so what I would like to happen is for the function to run on cell 'k' then to take paste the first line of output into another worksheet. Before moving to the next k I would like the contents of cell k + 1, (the cell directly below the cell using the formula) to be cleared. Here is my code, please note I have reduced the loop until I find the appropriate solution.
Sub bdX_R1()
Dim k As Long
Dim arrNames As Variant
Dim l As Long
Dim DestSheet1 As Worksheet
Set DestSheet1 = Worksheets("Sheet2")
arrNames = Range("A2:A18136").Value
For k = 2 To 18
Cells(k + 1, "F").Formula = "=bds(" & Chr(34) & arrNames(k, 1) & Chr(34) & ", " & _
Chr(34) & "BOND_CHAIN" & Chr(34) & ", " & Chr(34) & "dir = h" & Chr(34) & ")"
If Cells(k + 1, "F").Value = "#N/A N/A" Then
Cells(k + 1, "F").ClearContents
ElseIf Cells(k + 1, "F").Value = "N/A Invalid Security" Then
Cells(k + 1, "F").ClearContents
Else: Cells(k + 1, "F").Value.Copy Destination:=DestSheet1.Cells(k, "A")
Cells(k + 1, "B").Value.Copy Destination:=DestSheet1.Cells(k, "B")
Cells(k + 2, "F").ClearContents
End If
Next k
End Sub
I am using a Bloomberg function that gives its output on 2 lines (rows). The function is looping over a large number of cells so what I would like to happen is for the function to run on cell 'k' then to take paste the first line of output into another worksheet. Before moving to the next k I would like the contents of cell k + 1, (the cell directly below the cell using the formula) to be cleared. Here is my code, please note I have reduced the loop until I find the appropriate solution.
Sub bdX_R1()
Dim k As Long
Dim arrNames As Variant
Dim l As Long
Dim DestSheet1 As Worksheet
Set DestSheet1 = Worksheets("Sheet2")
arrNames = Range("A2:A18136").Value
For k = 2 To 18
Cells(k + 1, "F").Formula = "=bds(" & Chr(34) & arrNames(k, 1) & Chr(34) & ", " & _
Chr(34) & "BOND_CHAIN" & Chr(34) & ", " & Chr(34) & "dir = h" & Chr(34) & ")"
If Cells(k + 1, "F").Value = "#N/A N/A" Then
Cells(k + 1, "F").ClearContents
ElseIf Cells(k + 1, "F").Value = "N/A Invalid Security" Then
Cells(k + 1, "F").ClearContents
Else: Cells(k + 1, "F").Value.Copy Destination:=DestSheet1.Cells(k, "A")
Cells(k + 1, "B").Value.Copy Destination:=DestSheet1.Cells(k, "B")
Cells(k + 2, "F").ClearContents
End If
Next k
End Sub