Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5967995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:01:30+00:00 2026-05-22T20:01:30+00:00

For some reason, the code below fails on the second line with run-time error

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:01:30+00:00Added an answer on May 22, 2026 at 8:01 pm

    Try this instead, the only time your code caused errors for me was when the intersection ended up being empty.

    Dim c As Range, d As Range
    Dim rng As Range
    
    For Each c In Range("test1")
        Set rng = Application.Intersect(Rows(c.Row), Range("test2"))
        If rng Is Nothing Then
            '' Empty intersection ''
            Debug.Print "Empty"
        Else
            For Each d In rng
                '' some instructions here ''
                Debug.Print d.Address
            Next d
        End If
    Next c
    

    Of course you should probably also be prefixing your Range and Rows with the sheet, e.g:

    Sheet1.Rows
    

    and

    Sheet1.Range("test1")
    

    etcetera…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

See code below, for some reason it only works when I put a breakpoint
For some reason the following code fails. You can't simply erase a reverse_iterator by
The following html code works in Firefox, but for some reason fails in IE
for some reason the below code is outputting the correct ticker in the location
For some reason, Section 1 works but Section 2 does not. When run in
I have the following code: visitSite.hidden = YES; For some reason, when I click
I use the code below to insert data into my sqlite-database but for some
For some reason I never see this done. Is there a reason why not?
For some reason when I attempt to make a request to an Ajax.net web
For some reason when I create a new namespace in Visual Studio 2008 its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.