If Statement in loop

Yorke

New Member
Joined
Nov 29, 2021
Messages
19
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I am trying to write a simple If statement inside a loop which applies to all rows which have a value in Column A.

The if statement just needs to check if each cell in Column H is empty and if so paste the value from the same row in Column K. This needs to repeat for every row which there is a value in Column A for.

Here is my code:

LRS = ThisWorkbook.Worksheets("Status").Range("A" & Rows.Count).End(xlUp).Row
Dim Cell As Range

For Each Cell In Range("H2:H" & LRS)
If Cell.Value = "" Then
Cell.FormulaR1C1 = "=RC11"
End If
Next Cell

Thanks in advance, I'm a VBA noob and I've been searching all over for solutions!
 
Which column returns the #N/A?
I don't think you can compare anything to the #N/A error.

I would recommend wrapping your VLOOKUP formula in a IFNA function to return something other than an error when no match is found (see: IFNA function).

So, that structure would look something like:
Rich (BB code):
=IFNA(VLOOKUP(...),what to return if no match)

See if making that changes allows your code to run without error.

This works perfectly now, thank-you again! Your replies really help not only solve but learn!

Should I set your latest reply to solution, or leave as the first?
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
You are welcome.

Should I set your latest reply to solution, or leave as the first?
Just leave the first, as that is the one that answered the original question.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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