If cell value in a range is 0 then make another cell value equal another

pook_666

Board Regular
Joined
Aug 16, 2018
Messages
94
I am being an idiot and cannot for the life of me work out this simple VBA!!

I have a list of data starting from cell D16. If the value of cell D16 is zero, then I want E16 value to equal F16 value. Then I am trying to loop this in for every subsequent cell in D.

Below was my attempt and nothing happens...I know I'm being stupid here and missing something obvious, but just can't think!!

VBA Code:
Sub test()

Dim lrow As Long, cell As Range

lrow = Range("D16").End(xlUp).Row

For Each cell In Range("D16:D" & lrow)
If cell.Value = 0 Then
    cell.Offset(0, 1) = cell.Offset(0, 2).Value
    End If
Next cell

End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi Pook,

Try changing your lrow= line to this:

VBA Code:
lrow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "D").End(xlUp).Row

Change activesheet to whatever your sheet name is if necessary.
 
Upvote 0

Forum statistics

Threads
1,215,842
Messages
6,127,230
Members
449,371
Latest member
strawberrish

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