looping through a column and if cell value = Range(c4) then give value in next column

KNKN9

Board Regular
Joined
Mar 27, 2017
Messages
92
Hi,

I want to loop through a column and if the values in this cells are the same as my c4 cell value then I want all the corresponding values in column 34 in a a new column. I have the code below but all it does is give me the first value in the 34 column and repeats it.

Code:
For Each cell In Range("D:D")
If cell.Value = Worksheets("x").Range("C4").Value Then
Worksheets("y").Range("BD:BD") = cell.Offset(i, 34).Value
End If
Next


End Sub

Thanks in advance for your help
 
Hi,

I have one small adjustment to the code.

If I wanted to return the value into a different worksheet, how will I go about it ?. I have tried the code below but it only returns the first value and not all the values.

Code:
   If .Cells(x, 1).Value = C4 Then differentworksheet.Cells(17, 2).Value = .Cells(x, 38).Value

Try:
Code:
Sub Macro1()

    Dim x   As Long
    Dim LR  As Long
    Dim C4  As Variant
    
    C4 = Sheets("x").Cells(4, 3).Value
    
    Application.ScreenUpdating = False
        
    With Sheets("y")
        LR = .Cells(.Rows.Count, 1).End(xlUp).Row
        For x = 1 To LR
            If .Cells(x, 1).Value = C4 Then .Cells(x, 56).Value = .Cells(x, 38).Value
        Next x
    End With
    
    Application.ScreenUpdating = True
                
End Sub
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,216,780
Messages
6,132,669
Members
449,746
Latest member
signuptoignore

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