Compare Two column and put the value in 3rd column

ARUNCHENNAI

Board Regular
Joined
Apr 24, 2017
Messages
66
Hi,
I want the desired result in Z column though VBA
XYZ
PlanActualDesired Result
101010
0200
203020
304030
0500
4040
00
5050
600
00
00
00
700
800
900
00

<tbody>
</tbody>

My code is not working. Kindly help.
Code:
Sub test()Dim X As Range, Y As Range, Z As Range


For Each X In Range("A5:A20")
    For Each Y In Range("B5:B20")
        For Each Z In Range("C5:C20")
            If X = 0 Then
            Z = 0
            'End If
                    Else
                If X <> 0 Then
                Z = X.Value
            End If
            End If
        Next Z
    Next Y
Next X


End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Perhaps you could explain what is supposed to happen. From looking at your data, I do not see any kind of consistent relationship between the column values...
 
Upvote 0
igold, thank you for your time.
I'm sorry for not making the request clearly.

What I have is X column the plan data and Y column as actual data.
I need to display in Z column against X and Y row, if plan is 0 then Z column need to be filled with 0, else to fetch actual data in Z column in order.
 
Upvote 0
if X is not zero and Y is empty, what does Z equal...
 
Upvote 0
Hi,
I found a work around with below code.Forking fine.
Any suggestion to do do it better.
Code:
Sub test()
Dim x As Range
Dim i As String

For Each x In Range(""A1:A15")
i = x.Address
  If x = 0 Then
   Range(i).Offset(, 1).Insert Shift:=xlDown
  End If
  Next x
  MsgBox "Done"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

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