+ Reply to Thread
Results 1 to 13 of 13

Array loop producing error "Run time error '1004'"

  1. #1
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Thumbs up Array loop producing error "Run time error '1004'"

    Hi

    I have created the array loop below, which should go through the array and put each letter within in the place of the column letter within the lines of code.

    Please Login or Register  to view this content.
    However when i run it i get an error of "Method 'range' of 'object' '_global' failed"

    Does anyone know why i get this error?

    Thanks

    Jeskit
    Last edited by jeskit; 05-06-2011 at 08:57 AM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Array loop producing error "Run time error '1004'"

    Array("F") isn't an array
    Avoid using 'select' in VBA-code
    Probably you have a namedrange "F" (your information is rather scarce)
    If you implicitly declare an object variable 'sht2' it isn't obvious to refer to a variable 'sht3' in the code that follows.
    This could be your intention ?

    Please Login or Register  to view this content.



  3. #3
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Array loop producing error "Run time error '1004'"

    hi

    Thanks for replying. All working now!! However do you know if its possible to have two arrays in the same for loop??

    As i need one array for the column letter, but also need one for the column number in vlookup formula.

    Please Login or Register  to view this content.

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Array loop producing error "Run time error '1004'"

    Please read/study my post again to avoid 'select'.
    Last edited by snb; 05-06-2011 at 06:52 AM.

  5. #5
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Array loop producing error "Run time error '1004'"

    HI

    I have taken the first select statement out and placed it before hand but the second one can not be removed as the selection autofill doesn't work without it.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Array loop producing error "Run time error '1004'"

    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    Last edited by snb; 05-06-2011 at 06:55 AM.

  7. #7
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Array loop producing error "Run time error '1004'"

    Hi

    Would you code work if the array variable was placed inside the vlookup?

    Like?

    Please Login or Register  to view this content.

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Array loop producing error "Run time error '1004'"

    You can test it; I can't.
    Sure it's possible, but since you gave no information about what you want to achieve I can't say whether that will result in what you're aiming at.

  9. #9
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Array loop producing error "Run time error '1004'"

    Hi

    I tested it and itstead of a value i got #Value error in the cell.

    Basically i need to put a vlookup forumla in cells F2, K2, W2, X2 and Y2 which looks up the value in Cell A1 in the Range ConvertManual!$A$2:$Y$500 in columns 6, 11, 23, 24 and 25.

    Then once its placed them in the columns do an autofill on columns F2, K2, W2, X2 and Y2.

    This can be done by writing the same line of code for each column and then another line of code to autofill each column but i was hoping i could avoid that and use an array but it didn't seem to work within the Vlookup forumla.

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Array loop producing error "Run time error '1004'"

    The proof

    Please Login or Register  to view this content.

  11. #11
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Array loop producing error "Run time error '1004'"

    Hi

    I tried it and it works except it keeps putting the an N/A# in the cell above F2

  12. #12
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Array loop producing error "Run time error '1004'"

    - did you catch the difference between your code and mine and why you can't put a variable in a string just inserting its name ?
    - so what's the value in A1 ? that could explain why...., etc.

  13. #13
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Thumbs up Re: Array loop producing error "Run time error '1004'"

    Hi

    I have it working now i forgot about the headerline so it should have been looking at A2 not A1.

    Thanks for your help. I greatly appricated it

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1