Copy value from column A if value in column B at same position is X

torsten

New Member
Joined
Oct 16, 2013
Messages
3
Hello!

Im very new here. Have been trying for days to acomplish this.
I have e.g. 3 colums, A, B and C.
In columna A there is A number on every row.
In column B there is a number on ever row.

In column C I want to compile a new list such that if a number in column B is X (eg 1) the number from column A at the coresponding cell should be copied to column C. I want there to be no empyt cells in column C. So for the list below, the number in column A should be copied to C if its corresponding B cell is 0.

64064
64064
57057
62062
06664
64065
65064
06765
640
069
650

<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>
</tbody>


Thanks for any help!

T

<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>
</tbody>
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try this macro

Code:
Sub test()
Dim LR As Long, i As Long, j As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    With Range("A" & i)
        If .Offset(, 1).Value = 0 Then
            j = j + 1
            Range("C" & j).Value = .Value
        End If
    End With
Next i
End Sub
 
Upvote 0
Thankyou very much! This was exatcly was I was after. There is one problem which I did not present. In the column A there are also som values with "0" which should not be copied. How can I exclude them?

Thanks for the great help!

Torsten
 
Upvote 0
Try

Code:
Sub test()
Dim LR As Long, i As Long, j As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    With Range("A" & i)
        If .Value <> 0 And .Offset(, 1).Value = 0 Then
            j = j + 1
            Range("C" & j).Value = .Value
        End If
    End With
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,790
Members
449,468
Latest member
AGreen17

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