guilhermelemos
New Member
- Joined
- Oct 7, 2013
- Messages
- 11
Hi,
I am trying to create a lookup that will get the parts with the highest chance of being used depending on the location.
I figured out the formula in Excel, but I needed to convert into VBA. I used the recorder, but I need to add a variable to the formula, so the lookup value of my formula is correct.
I am getting the following error.
Run-time error '1004'
Application-defined or object-defined error
I think it's because the syntax of my formula is not correct when I reference the variable i.
Can anyone help?
Thanks in advance.
Sub Additional_Parts_Small_Locations()
Dim strRng As String
Dim i As Integer
i = 2
Windows("FSL quantity template attempt2.xlsm").Activate
Sheets("Locations").Select
Sheets("Locations").Calculate
Range("A2").Select
Do While i < 43
If ActiveCell.Offset(0, 2) < 10 Then
Sheets("Summary").Select
Range("A600000").End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = _
"=INDEX(INDIRECT(ADDRESS(1,1,,,""[Printers vs parts consumption_roundup.xlsx]Parts ranking per location"")&"":""&ADDRESS(20000,MATCH(Locations!RiC1 ,'[Printers vs parts consumption_roundup.xlsx]Parts ranking per location'!R1C1:R1C42,0))),MATCH(1,INDIRECT(ADDRESS(1,MATCH(Locations!RiC1,'[Printers vs parts consumption_roundup.xlsx]Parts ranking per location'!R" & _
"2,0),,,""[Printers vs parts consumption_roundup.xlsx]Parts ranking per location"")&"":""&ADDRESS(20000,Locations!RiC1,'[Printers vs parts consumption_roundup.xlsx]Parts ranking per location'!R1C1:R1C42,0))),0),1)"
End If
i = i + 1
ActiveCell.Offset(1, 0).Select
Loop
End Sub
I am trying to create a lookup that will get the parts with the highest chance of being used depending on the location.
I figured out the formula in Excel, but I needed to convert into VBA. I used the recorder, but I need to add a variable to the formula, so the lookup value of my formula is correct.
I am getting the following error.
Run-time error '1004'
Application-defined or object-defined error
I think it's because the syntax of my formula is not correct when I reference the variable i.
Can anyone help?
Thanks in advance.
Sub Additional_Parts_Small_Locations()
Dim strRng As String
Dim i As Integer
i = 2
Windows("FSL quantity template attempt2.xlsm").Activate
Sheets("Locations").Select
Sheets("Locations").Calculate
Range("A2").Select
Do While i < 43
If ActiveCell.Offset(0, 2) < 10 Then
Sheets("Summary").Select
Range("A600000").End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = _
"=INDEX(INDIRECT(ADDRESS(1,1,,,""[Printers vs parts consumption_roundup.xlsx]Parts ranking per location"")&"":""&ADDRESS(20000,MATCH(Locations!RiC1 ,'[Printers vs parts consumption_roundup.xlsx]Parts ranking per location'!R1C1:R1C42,0))),MATCH(1,INDIRECT(ADDRESS(1,MATCH(Locations!RiC1,'[Printers vs parts consumption_roundup.xlsx]Parts ranking per location'!R" & _
"2,0),,,""[Printers vs parts consumption_roundup.xlsx]Parts ranking per location"")&"":""&ADDRESS(20000,Locations!RiC1,'[Printers vs parts consumption_roundup.xlsx]Parts ranking per location'!R1C1:R1C42,0))),0),1)"
End If
i = i + 1
ActiveCell.Offset(1, 0).Select
Loop
End Sub