+ Reply to Thread
Results 1 to 6 of 6

Error while using loop and offset functions

  1. #1
    Registered User
    Join Date
    01-10-2012
    Location
    ntrques ous
    MS-Off Ver
    Excel 2003
    Posts
    3

    Error while using loop and offset functions

    Hello everyone:

    I'm currently working on what is suppose to be an easy macro program but for the life of me I can't figure out what's going wrong.

    Okay here goes. Currently for the sake of simplicity I have two files involved in the macro. The overall purpose is just to copy certain cells from one to the other.
    The current Excel file (also the one where the macro code is being written in) is called 'SampleExcelErrorFile.xls' and I want certain cells on the first sheet of this file, "Toronto" to be filled from another excel file, named "JanFebData_5AM_Issue.xls". Now, the cells being copied and pasted are not adjacent cells, and I must copy and paste cells from "JanFebData_5AM_Issue.xls" that are in rows with increments of 125 cells (e.g copy cell A1, then A125, A250, etc). And I want to paste these cells into column A of the file 'SampleExcelErrorFile.xls' that moves down 1 cell at a time (e.g B4, B5, B6, etc).

    Below is part of the code that does this copying and pasting.

    Please Login or Register  to view this content.
    When I run the program, the following error pops up:

    "Run-time error '-2147221080(800401a8)': Automation Error"


    And other times when I run it, another error sometimes pop up saying something like "Runtime error 424, Object Required"

    Given that I just started learning about macros a week ago, is there something wrong with my copy-and-paste function above using loop? Any help would be greatly appreciated!
    Last edited by Fei.R; 01-19-2012 at 11:12 PM.

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Error while using loop and offset functions

    Try this first,

    Please Login or Register  to view this content.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  3. #3
    Registered User
    Join Date
    01-10-2012
    Location
    ntrques ous
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Error while using loop and offset functions

    ^ Thank you so much for your quick reply!

    However, the same error pops up "Run-time error '-2147221080(800401a8)' Automation Error"

    I noticed that i start with i=0 to 58, would the initial value of i=0 be the cause?

  4. #4
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Error while using loop and offset functions

    Try this code,

    paste it in a new module an run it.

    Please Login or Register  to view this content.
    But, if you want your original code modified, post the whole sub.
    Last edited by JapanDave; 01-19-2012 at 08:46 PM.

  5. #5
    Registered User
    Join Date
    01-10-2012
    Location
    ntrques ous
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Error while using loop and offset functions

    ^ Hey JapanDave:

    I found the error. Apparently i=1 to 58 instead of i=0 to 58 solves the issue!

    Thank you for your help!

  6. #6
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Error while using loop and offset functions

    Please mark the thread solved.

+ 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