PDA

View Full Version : Solved: Adding Formula into Loop



inajica
09-24-2008, 02:36 PM
I am tring to add the following statements into my loop:

LastRow = Range("A65536").End(xlUp).Row
Range("g2:g" & LastRow).FormulaR1C1 = "1"

LastRow = Range("A65536").End(xlUp).Row
Range("g2:g" & LastRow).FormulaR1C1 = "2"

LastRow = Range("A65536").End(xlUp).Row
Range("g2:g" & LastRow).FormulaR1C1 = "3"

These FormulaR1C1 goes up to fifty. So it would be easier to put them into a loop, if possible. This is the For loop I have so far.


Dim open1 As String

open1 = "C:\Recent\40Copy\1_9-20-08\50"

For i = 1 To 50

Workbooks.Open Filename:=open1 & "\win01_" & i & ".xlsx"
Call call1part1

Next i


Thank you for any help.

Bob Phillips
09-24-2008, 02:39 PM
Wat is the point of a loop that sets them all to 1, then to 2, then to ... 50. Why not just set them all to 50 and be done with it?

inajica
09-24-2008, 02:51 PM
Each time I open a file(I have fifty of them), I copy the data into a new workbook. And I need to keep track of which files that I opened so I used that formula.

Bob Phillips
09-24-2008, 02:53 PM
Is this what you mean?



Dim open1 As String

open1 = "C:\Recent\40Copy\1_9-20-08\50"

For i = 1 To 50

Workbooks.Open Filename:=open1 & "\win01_" & i & ".xlsx"
LastRow = Range("A65536").End(xlUp).Row
Range("g2:g" & LastRow).FormulaR1C1 = i
Call call1part1
Next i

inajica
09-24-2008, 03:15 PM
Thanks, that worked great.