+ Reply to Thread
Results 1 to 4 of 4

Get Run-Time Error 1004 With Simple Macro

  1. #1
    Registered User
    Join Date
    04-22-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    15

    Get Run-Time Error 1004 With Simple Macro

    I first saw an Excel spreadsheet three days ago, so this is a real beginner's question. I recorded a simple macro to select data from five (non-consecutive) cells in a row in one workbook, enter the data in the appropriate place in a second workbook, and then colour the source cells in the first workbook yellow as a reference. That all works well. But when I try to have the macro move down to the next row in the first workbook containing data that I want before it (the macro) ends, so that I don't have to use the mouse at all and can just keep hitting the keyboard command, I get run-time error 1004. So, most of all I'd like to know how to make this macro work. I'd also appreciate advice, though it's less critical, on how to make the macro loop through the process X times for X rows, so that the whole process would only take one keyboard command. That would be very satisfying.

    Thanks in advance, and this is the VBA code for the macro with the extra step that doesn't work:

    Please Login or Register  to view this content.
    Last edited by Paul; 04-22-2012 at 07:43 AM. Reason: Added CODE tags for new user. Please do so yourself in the future.

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: First Post: Get Run-Time Error 1004 With Simple Macro

    Hi and welcome to the forum.

    Nasty stuff first - could you read the forum rules and use code tags when posting code, please?

    OK, with that out of the way, on with your problem ... I think your immediate problem can be fixed just by changing the line:

    Please Login or Register  to view this content.
    To:

    Please Login or Register  to view this content.
    As for making the code run over multiple lines - the issue with the macro recorder is that it records macros with a lot of unnecessary code in. Your whole thing can be re-written as just a couple of lines of code. Are you always writing to the same sheet in the target workbook? If so, which sheet is it?

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

    Re: First Post: Get Run-Time Error 1004 With Simple Macro

    In this case, "Range("A1").Select" isn't selecting the actual cell A1. It is selecting the first (top left most) cell in the range specified. As Andrew said, though, this code could likely be shortened considerably if you tell us - or better yet SHOW us in a sample workbook - what cells should be moved where, which should be colored, and how far you want to continue down rows (as far as your data goes down, or just one row each time you run the macro)?

  4. #4
    Registered User
    Join Date
    04-22-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Get Run-Time Error 1004 With Simple Macro

    Thank you, gentlemen. You've pointed me in the right direction and I can do everything I need to now.

+ 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