For some reason, the code below does not work on the second line with an error of "1004" at runtime, specifying the "Intersection" method of the "_Application" object failed and in some cases when I tried to change the code that it produces a '_Global'. The strangest thing is that I played with different versions of this code, and sometimes after many changes during debug mode, I repeated this form and then it starts. If I try to re-run the code, it will work again.
rng1 is a set of cells from the same column, rng2 is a set of cells across several columns with the same rows as rng1
eg. rng1 = {A2: A10}, rng2 = {D2: H10}
The instructions store the values of cells from a single row in rng2 relative to a single record in rng1 in an array. I checked that the ranges are on the same sheet, valid and (where named) refer to 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
source
share