klovink001
New Member
- Joined
- Jul 30, 2019
- Messages
- 4
Hi everyone,
Im relatively new to VBA, and struggling a bit with the syntax. Hope someone can help!
What im trying to do is this: I have 3 sheets im working with, lets call them sheet1, sheet2 and sheet3. Sheet 1 is input data in which I want to look up a value, for every row in sheet 2. Sheet 3 is the auxiliary (Aux) sheet where I want to do the index-match, and afterwards copy the value to the relevant row on sheet 2. Sheet 2 has over 40.000 rows, so I let i run untill 50.000 to be sure.
This is what I have now:
Unfortunately im getting the following error: 'Run-time error '1004': Application defined or object defined error'. The script breaks at the line with the INDEX-formula.
This might be a relatively common mistake im making, but again Im not yet experienced is this business. Any ideas?
Im relatively new to VBA, and struggling a bit with the syntax. Hope someone can help!
What im trying to do is this: I have 3 sheets im working with, lets call them sheet1, sheet2 and sheet3. Sheet 1 is input data in which I want to look up a value, for every row in sheet 2. Sheet 3 is the auxiliary (Aux) sheet where I want to do the index-match, and afterwards copy the value to the relevant row on sheet 2. Sheet 2 has over 40.000 rows, so I let i run untill 50.000 to be sure.
This is what I have now:
Code:
Sub Loop3()'
' Loop3 Macro
'
'
Dim i As Integer
Dim startrow As Integer
startrow = 10
i = 0
Application.ScreenUpdating = False
Do While i < 50000
Worksheets("Aux").Activate
Worksheets("Aux").Range("G7").Select
ActiveCell.ClearContents
ActiveCell.FormulaR1C1 = _
"=INDEX('Sheet1'!R10C2:R4403C6,MATCH('Sheet2'!R[3+i]C[-5],'Sheet1'!R[3]C[-5]:R[4396]C[-5],0),4)"
Worksheets("Aux").Range("G7").Select
Selection.Copy
Worksheets("Sheet2").Range("AU" & startrow + i).Select
ActiveCell.Paste
i = i + 1
Loop
End Sub
Unfortunately im getting the following error: 'Run-time error '1004': Application defined or object defined error'. The script breaks at the line with the INDEX-formula.
This might be a relatively common mistake im making, but again Im not yet experienced is this business. Any ideas?