Hi. I just learned how to use For Each...Next loops to replace If...Then loops
Since it is best to avoid loops, I am looking for a way to solve this problem using VBA, without a loop.
Book2.xlsm
There is a simple code inside.
1) Column C is a direct copy of Column B.
2) For every cell in Column B which contains '0' I need to copy the corresponding cell from Column A and paste it in Column C
3) For example: if cell B61 = 0, copy A61, paste in C61
----------------------------------------------------
Here is the code from the xlsm file. YES, there is a reason I am not just doing =IF(B1=0, C1=A1). There are about a million other things I have to do if B = 0 and I am 99% sure I cant do them using built in Excel functions.
![]()
Option Explicit Sub macro1() Dim i As Integer i = 0 Dim target, cell As Range Set target = Range("b4:b3234") For Each cell In target If cell.Value = i Then Cells(cell.Row, 3) = Cells(cell.Row, 1) End If Next cell End Sub
Once again, looking for a faster alternative to loops. Thx, Niko
Bookmarks