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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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