Looping through cells that are blank but have formula ?

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
785
Office Version
  1. 365
Platform
  1. Windows
Hi,
having trouble with this one

basically i have a column (J) of cells with the following formula
Code:
=IFERROR(INDEX(B2:$B$10000,MATCH(I2,F2:$F$10000,0)),"")

and i want to write values into all the cells that are blank

something like:
Code:
Sub test()
Dim r As Range
For Each r In Range("J2:J10000")
    If r = "" and r.Offset(0, -1).value < 10 then
    r = r.Offset(0, -1).value + 10
    End If
Next
End Sub

ive tried
if r = 0
if len(r) = 0
if isblank(r)

no luck

any help appreciated
 
Last edited:

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.
Why not just change your if Error statement to return a unique string so you can find it that way. So change the "" at the end of your formula to "No Value" and then modify the VBA to If R= "No Value"


Hi,
having trouble with this one

basically i have a column (J) of cells with the following formula
Code:
=IFERROR(INDEX(B2:$B$10000,MATCH(I2,F2:$F$10000,0)),"")

and i want to write values into all the cells that are blank

something like:
Code:
Sub test()
Dim r As Range
For Each r In Range("J2:J10000")
    If r = "" and r.Offset(0, -1).value < 10 then
    r = r.Offset(0, -1).value + 10
    End If
Next
End Sub

ive tried
if r = 0
if len(r) = 0
if isblank(r)

no luck

any help appreciated
 
Upvote 0
Why not just change your if Error statement to return a unique string so you can find it that way. So change the "" at the end of your formula to "No Value" and then modify the VBA to If R= "No Value"

Could do that or even use an helper column, just thought there would be a simple way to do this without modifying my Sheets

If it helps, without the IFERROR , "" , the cell would display #NA
 
Last edited:
Upvote 0
Your code should work.
In an unused cell put
=LEN(J2)
& point it at one of the "Blank" cells in col J, what does it return?
 
Upvote 0
Thanks all

I ended up modifying my formula to output zero instead of ""

Then custom formatting to hide the zeros

It now works :) though currently the loop is very slow
I can probably speed it up by disabling screen updating / calcs

Though is there a better way to do the loop?
 
Upvote 0
Copy the range into an array like: RngArray= Range("J2:J10000").value

That creates a twodimensional array RngArray(1,1)= J2, RngArray(2,1)=J3 etc
Do your loop on the array.
When finished write the array back to the range: Range("J2:J10000").value=RngArray

 
Upvote 0

Forum statistics

Threads
1,216,222
Messages
6,129,589
Members
449,520
Latest member
TBFrieds

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