For some reason, the code below fails on the second line with run-time error ‘1004’ stating “Method ‘Intersect’ of object ‘_Application’ failed” and on some occasions where I have tried to amend the code it produces a ‘_Global’ failure. The stranger thing is that I have played with various versions of this code and sometimes after many changes during debug mode I retried this form and then it runs. If I then try to rerun the code it fails again.
rng1 is a set of cells from the same column, rng2 is a set of cells over multiple columns with the same rows as rng1
e.g. rng1 = {A2:A10},
rng2 = {D2:H10}
The instructions saves the values of cells from within a single row of rng2 with respect to an individual entry in rng1 into an array. I have checked that the ranges are on the same sheet, valid and (where named) are referencing the correct cells.
For Each c In Range("rng1").Cells
For Each d In Application.Intersect(Rows(c.Row), Range("rng2")).Cells
*some instructions here*
Next d
Next c
Try this instead, the only time your code caused errors for me was when the intersection ended up being empty.
Of course you should probably also be prefixing your
RangeandRowswith the sheet, e.g:and
etcetera…