IF(ISERROR) in an array

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,924
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have these formulae in cells:

Code:
=IF(ISERROR(A1/B1),0,A1/B1)

=IF(ISERROR(C1/D1),0,C1/D1)


How can I create this in a VBA array?

For Example:

Code:
Dim DataArray() As Variant

DataArray = Cells(1,1).CurrentRegion.Value

Dim MyArray(1 To 10, 1 To 2) As Variant

Dim Counter As Integer

On Error GoTo ErrHandler

For Counter = 1 To 10

    MyArray(Counter, 1) = DataArray(Counter, 1) / DataArray(Counter, 2)
    MyArray(Counter, 2) = DataArray(Counter, 3) / DataArray(Counter, 4)

Next Counter

Exit Sub

ErrHandler:

MyArray(Counter, 1) = 0
MyArray(Counter, 2) = 0

Resume Next

If only B1 OR D1 is zero, it will error out but how can my array know which one errors?

Thanks
 
Last edited:
Sorry but if my original formula was different, say:

Code:
=IF(ISERROR(IF(A2>Z100,E2,E2/F2),0,IF(A2>Z100,E2,E2/F2))

then if A2 was a letter, say p but Z100 is the value 1000, it does NOT error.

Ok. This is a different formula. Adapt the code as needed.
Next time, please, show us the actual scenario you are working with and all the conditions involved.

M.
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,223,909
Messages
6,175,314
Members
452,634
Latest member
cpostell

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