VBA to Loop through a Column based on a value

Minerva93

New Member
Joined
May 21, 2018
Messages
2
I'm trying to write a sub that loops through the values in the C column of the "Changes" worksheet and looks for the corresponding value in the "4Q2017" worksheet. If there is a match, the cell two columns away in the "Changes" worksheet should take the value 72 columns away from the matched value in the "4Q2017" worksheet.

I have an "object required" error; how can I improve this code? Thank you!


Code:
Sub GetData()
Dim rng1 As Range, rng2 As Range, cell As Range, cell2 As Range
Set rng1 = Worksheets("Changes").Range("A3:A100")
Set rng2 = Worksheets("4Q2017").Range("C2:C100")
For Each cell In rng
    If Not IsEmpty(cell.Value) Then
        For Each cell2 In rng2
            If cell2.Value = cell Then
                cell.Offset(0, columnOffset:=2) = cell2.Offset(0, 72).Value
            End If
        Next cell2
    End If
Next cell
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Silly error- I just need to change the "rng" reference to "rng1". Sorry, please disregard and delete this thread.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,022
Latest member
RobertV1609

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top