Sub rs()
Dim i As Integer
Dim randomVar As Variant
Dim ra As Variant
'Set ra = New Range
For i = 4 To 30
If IsEmpty(Range("B" & i).Value) = True Then GoTo line1
Range("B" & i).Select
randomVar = ActiveCell.Value 'stores name of project to be found in another worksheet
Sheets("Sheet2").Select
Set ra = Cells.Find(randomVar) 'finds project name
If ra Is Nothing Then GoTo line1 'if not found continue for loop
ra.Offset(columnOffset:=4).Copy 'copies found project's cost that is 4 colums right to the project name
Sheets("Sheet1").Select
Range("F" & i).Select
ActiveSheet.Paste 'pastes the cost of the project from other sheet
line1:
Next i
End Sub
Overview of what the code does:
The above code copies project name from sheet1 and looks for it in sheet2. If the project is found it copies the cost of the project that is 4 columns after the project name, and pastes that cost in sheet1 next to its respective project.
Problem:
It correctly places first few values in place in sheet1 but after that it crashes. Gives no error just picks wrong values from sheet2 and places in sheet 1. What could possibly be happening?