i am trying to build a vba program in which i have 3 worksheets : sheet 1, sheet2 and sheet3, i will input the data in sheet 2 (column A : column E) and i want to copy first 500 rics to be copied from sheet 2 (column B) in sheet 1 (column A) and what ever the result comes based on refinitv formula in sheet 1 (column D : column G) should get copied to sheet 3 , then again the macro should go to sheet 2 copy the next 500 rics then paste it in sheet 1 column A and what ever the result comes should get pasted in sheet 3, this process should run untill all the rics are covered in sheet 2. for example if sheet 2 has total of 1200 rics then the loop will run thrice (500 + 500+ 200 = 1200). the only help i need is in the for loop section rest i will try on my own.
rewriting the sequence for better understanding: sheet 2 : i will input the data, the macro should should pick first 500 rics from column B and paste those in sheet 1 , column (A2) then the eikon formula will fetch the result based on column A and macro should copy the result in sheet 3 then again the next 500 rics from sheet 2 gets picked and the same process should be followed.
Sub CAEvents()
Application.ScreenUpdating = False
Dim wb As Workbook, ws As Worksheet, wsRic As Worksheet, ws1 As Worksheet
Dim iLastRow As Long, r As Long, n As Long, i As Integer
Dim ric As String
Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet1")
Set ws1 = wb.sheeets("Sheet2") ' as appropriate
'n = ws.Range("B2").Value ' days
ThisWorkbook.Sheets("Sheet1").Range("A2:E50000").ClearContents
'ThisWorkbook.Sheets("Output").Cells.ClearContents
'ThisWorkbook.Sheets("InsertSeveralSpots").Range("B6:F6").End(xlDown).clearcontent
' loop through rics in col I
iLastRow = ws1.Cells(Rows.Count, "A").End(xlUp).Row
If iLastRow >= 2 Then
For r = 2 To iLastRow
ric = ws.Cells(r, "I")
ws.Range("A2").Value2 = ric
ws.Range("C1").FormulaR1C1 = "=@RHistory(R2C1,"".Timestamp;.Close"",""NBROWS:""&R2C2&"" INTERVAL:1D"",,""SORT:ASC TSREPEAT:NO CH:In;fd"",R[5]C)"
Application.Run "EikonRefreshWorksheet"
Application.Wait (Now + TimeValue("0:00:02"))