+ Reply to Thread
Results 1 to 11 of 11

Excel 2003 vs. 2007 VBA Issue

  1. #1
    Registered User
    Join Date
    11-18-2009
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    5

    Unhappy Excel 2003 vs. 2007 VBA Issue

    I have written the following code to take lines of data off a "Master" tab and create separate "forms" that are prepopulated from the original data. It should only create/pre-fill as many forms as there are lines of data in the Master tab. This code works beautifully on my Excel 2007 at home, but I need it to work on Excel 2003 at the office. No luck.

    Please correct the code so that it'll work on both!

    Thanks so much!!

    Please Login or Register  to view this content.
    Last edited by astronautika; 11-18-2009 at 04:02 PM.

  2. #2
    Registered User
    Join Date
    11-18-2009
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Excel 2003 vs. 2007 VBA Issue

    Sorry forgot to post the error...Runtime Error 9: Subscript out of Range at the following point:
    Please Login or Register  to view this content.
    ...and, again, works fine on Excel 2007. No errors!
    Last edited by Paul; 11-18-2009 at 04:09 PM. Reason: Added code tags

  3. #3
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Excel 2003 vs. 2007 VBA Issue

    I don't have 2003 any longer to test, but try changing:
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Be sure to change the rest of the rows that use that format. Not sure why you would need the "Item" section in either version.

  4. #4
    Registered User
    Join Date
    11-18-2009
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Excel 2003 vs. 2007 VBA Issue

    No luck, unfortunately...same error. Thanks though!

  5. #5
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Excel 2003 vs. 2007 VBA Issue

    You DIM'd variable x as Range, but you're trying to use it in a loop. I'm guessing you're trying to set the upper limit of the loop to the value in cell F2? If so, just DIM variable x as Long. (y and z, too. Long is usually safer than Integer, since it has a much greater range.)

  6. #6
    Forum Contributor
    Join Date
    04-01-2009
    Location
    Irvine, CA
    MS-Off Ver
    Excel 2010
    Posts
    280

    Re: Excel 2003 vs. 2007 VBA Issue

    I tried this in 2003 and 2007 and in both cases the Workbooks.Item(1). reference caused the error you described. If I removed that part the code would continue.

    Also, the code failed on the select statements (like):

    Please Login or Register  to view this content.
    If you remove the quotes it works:
    Please Login or Register  to view this content.
    Or you could just select the range without the string variable:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-18-2009
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Excel 2003 vs. 2007 VBA Issue

    Got a new error, but it feels like progress! I apologize...I'm very new to VBA code, but trying to plug my way through!

    As I was getting an "Object Required" error, I did some reading and got rid my "Set" here
    Please Login or Register  to view this content.
    I also changed the code to remove the quotes as Chance suggested.

    Now, I've got this code:
    Please Login or Register  to view this content.
    And, I get this error "Runtime Error 1004: Application-defined or object-defined error" at:
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    04-01-2009
    Location
    Irvine, CA
    MS-Off Ver
    Excel 2010
    Posts
    280

    Re: Excel 2003 vs. 2007 VBA Issue

    What data is being displayed in Worksheets("Master").Range(CorrectiveAction)?

    If there is Text in that cell it probably would give an error.
    If you are trying to copy text, then use ActiveCell.Value instead of ActiveCell.FormulaR1C1.

  9. #9
    Registered User
    Join Date
    11-18-2009
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Excel 2003 vs. 2007 VBA Issue

    It is text. In fact, all of what's being copied is text except maybe a date. The new code (below) will copy two sheets (there should be 17 for the 17 rows of data in my master tab) before generating the error.

    Please Login or Register  to view this content.
    Error "Run-time error '1004': Application-defined or object-defined error" at
    Please Login or Register  to view this content.

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Excel 2003 vs. 2007 VBA Issue

    As near as I can tell, this code does what you're trying to do.

    If it doesn't, step through it line by line to debug to see where it goes off the rails, and what the variables are when that happens.
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  11. #11
    Forum Contributor
    Join Date
    04-01-2009
    Location
    Irvine, CA
    MS-Off Ver
    Excel 2010
    Posts
    280

    Re: Excel 2003 vs. 2007 VBA Issue

    I agree with shg, the code works for me.
    Can you post a dummy file so we can see if your data is causing the error?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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