Looping through cells that are blank but have formula ?

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
788
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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
If you're happy getting rid of the iferror so that the cells return #N/A, you could use this
Code:
Sub test()
Dim r As Range
For Each r In Range("J2:J10000").SpecialCells(xlFormulas, xlErrors)
    If r.Offset(0, -1).Value < 10 Then
    r = r.Offset(0, -1).Value + 10
    End If
Next
End Sub
 
Upvote 0
Thanks Fluff, though I think to keep the errors hidden.

I have another criteria for the loop, which not sure if could speed things up.

Only values (S2:S50) which are found in column C (C2:C10000)

Maybe create a dictionary of the S2:S50 values
 
Last edited:
Upvote 0
I don't see what connection there is between cols S & C and Col J

i changed columns to make it easier to understand, here is my code currently:
Code:
Sub test()
Dim r As Range
For Each r In Range("J2:J10000")
    If r.Value = 0 And r.Offset(0, -1).Value > 0 And r.Offset(0, -1).Value < 10 Then
    r = r.Offset(0, -1).Value + 10
    End If
Next
End Sub

Which outputs like:
b25f7a960e.png


however i only want the loop to affect names found in the column (M)

so output should be like:
e8ff0adc27.png


thanks for any help
 
Last edited:
Upvote 0
Hello Jumbo,

Since you are already using formulas, why not use a formula in column "J"?

I copied this into J2 and dragged it down. It would be easier to use a dynamic named range for the cells in column "M". It would allow you to edit column "M" without needing to update the formulas.

=IF(ISERROR(MATCH($H2,$M$2:$M$4,0)),"",IF(AND($I2>0,$I2<10),$I2+10,""))
 
Upvote 0
Hello Jumbo,

Since you are already using formulas, why not use a formula in column "J"?

I copied this into J2 and dragged it down. It would be easier to use a dynamic named range for the cells in column "M". It would allow you to edit column "M" without needing to update the formulas.

=IF(ISERROR(MATCH($H2,$M$2:$M$4,0)),"",IF(AND($I2>0,$I2<10),$I2+10,""))

Thanks for the reply though this isn't an option with my sheet.
I need to keep the existing formulas but be able to manually write the values to the cells with the loop.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,206
Members
453,022
Latest member
RobertV1609

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