ARUNCHENNAI
Board Regular
- Joined
- Apr 24, 2017
- Messages
- 66
Hi,
I want the desired result in Z column though VBA
[TABLE="width: 254"]
<tbody>[TR]
[TD]X[/TD]
[TD]Y[/TD]
[TD]Z[/TD]
[/TR]
[TR]
[TD]Plan[/TD]
[TD]Actual[/TD]
[TD]Desired Result[/TD]
[/TR]
[TR]
[TD="align: right"]10[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]10[/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD="align: right"]20[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]20[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]20[/TD]
[/TR]
[TR]
[TD="align: right"]30[/TD]
[TD="align: right"]40[/TD]
[TD="align: right"]30[/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD="align: right"]50[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]40[/TD]
[TD][/TD]
[TD="align: right"]40[/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]50[/TD]
[TD][/TD]
[TD="align: right"]50[/TD]
[/TR]
[TR]
[TD="align: right"]60[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]70[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]80[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]90[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[/TR]
</tbody>[/TABLE]
My code is not working. Kindly help.
I want the desired result in Z column though VBA
[TABLE="width: 254"]
<tbody>[TR]
[TD]X[/TD]
[TD]Y[/TD]
[TD]Z[/TD]
[/TR]
[TR]
[TD]Plan[/TD]
[TD]Actual[/TD]
[TD]Desired Result[/TD]
[/TR]
[TR]
[TD="align: right"]10[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]10[/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD="align: right"]20[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]20[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]20[/TD]
[/TR]
[TR]
[TD="align: right"]30[/TD]
[TD="align: right"]40[/TD]
[TD="align: right"]30[/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD="align: right"]50[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]40[/TD]
[TD][/TD]
[TD="align: right"]40[/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]50[/TD]
[TD][/TD]
[TD="align: right"]50[/TD]
[/TR]
[TR]
[TD="align: right"]60[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]70[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]80[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]90[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[/TR]
</tbody>[/TABLE]
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