+ Reply to Thread
Results 1 to 4 of 4

Loop through a range of another sheet of the same workbook to change cell values

  1. #1
    Registered User
    Join Date
    01-14-2009
    Location
    Earth
    MS-Off Ver
    2007
    Posts
    43

    Loop through a range of another sheet of the same workbook to change cell values

    Alright, I've been playing with this for a while. Where am I going wrong? Basically, all I want to do is have this function to find the last row of copied data, and concatenate some cells and change the value of some cells.

    I get this error when I run the code below...
    Run-time error '1004': Method 'Range' of object '_Worksheet' failed
    Please Login or Register  to view this content.
    Last edited by flipjarg; 11-04-2014 at 11:06 AM. Reason: Solved!

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Loop through a range of another sheet of the same workbook to change cell values

    Hi flipjarg,

    1. I found problems in the following lines:
    Please Login or Register  to view this content.
    2. To prevent typos from ruining days and weeks of work 'Option Explicit' is NEEDED at the top of each code module. This prevents errors caused by missspellings and FORCES every variable to be DECLARED (e.g. dim i as Integer). http://www.cpearson.com/excel/DeclaringVariables.aspx

    3. It probably doesn't make any difference in this case, but in Excel 2007 the number of lines can overflow the Integer type. Row numbers should be type 'Long'.
    Please Login or Register  to view this content.
    4. After the 'PasteSpecial' line, the clipboard buffer should probably be cleared.
    Please Login or Register  to view this content.
    Lewis
    Last edited by LJMetzger; 10-29-2014 at 05:08 PM.

  3. #3
    Registered User
    Join Date
    01-14-2009
    Location
    Earth
    MS-Off Ver
    2007
    Posts
    43

    Re: Loop through a range of another sheet of the same workbook to change cell values

    Quote Originally Posted by LJMetzger View Post
    1. I found problems in the following lines:
    Please Login or Register  to view this content.
    Thanks for your reply and for pointing that out. That should have been more obvious to me ... I was working on other code that day as well and for some reason I was consistently doing this in all of my code that day. A good sign I had my head in VBA for too long in one sitting

    Quote Originally Posted by LJMetzger View Post
    2. To prevent typos from ruining days and weeks of work 'Option Explicit' is NEEDED at the top of each code module. This prevents errors caused by missspellings and FORCES every variable to be DECLARED (e.g. dim i as Integer). http://www.cpearson.com/excel/DeclaringVariables.aspx

    3. It probably doesn't make any difference in this case, but in Excel 2007 the number of lines can overflow the Integer type. Row numbers should be type 'Long'.
    Please Login or Register  to view this content.
    4. After the 'PasteSpecial' line, the clipboard buffer should probably be cleared.
    Please Login or Register  to view this content.
    Thanks for these other tips. I'm learning VBA as I go, as needed. I am definitely going to start using these.

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Loop through a range of another sheet of the same workbook to change cell values

    I'm glad I could be of some help.

    It's surprising how much smarter I get sometimes after a good night's sleep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro to Loop through range, change values
    By Student1990 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-21-2014, 12:43 PM
  2. Copy cell values until change of value with loop
    By sdadswell in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2011, 08:40 PM
  3. Live Transfer a range of cell values to another Sheet or to another Workbook
    By phstol in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-10-2009, 12:00 PM
  4. How to change values of userdefined cell names in a loop?
    By 77anders in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-05-2009, 10:21 AM
  5. Change workbook sheet reference using cell A1 to change a vairable
    By Reed in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-20-2005, 04:06 PM

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