+ Reply to Thread
Results 1 to 4 of 4

Consolidate Repetitive Macros using Variable and loop

  1. #1
    Registered User
    Join Date
    12-26-2011
    Location
    San Diego, CA
    MS-Off Ver
    Excel for 365
    Posts
    62

    Consolidate Repetitive Macros using Variable and loop

    Hi,

    I have attached a sample. This is a basic macro that copy's from the "Line" Tabs & Pastes to the "Prior Line" tabs. I'm calling out each tab by name in separate macros and wanted to try to consolidate it and make it better. There are a few other tabs in the workbook that do not have to be changed at all. Any help would be appreciated. Thanks
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Consolidate Repetitive Macros using Variable and loop

    Replace all of your code with this (tested).

    Also, variable lr was undeclared. I strongly recommend to everyone that they use Option Explicit and declare variables. Doing so prevents a lot of bugs and runtime errors.

    Please Login or Register  to view this content.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    12-26-2011
    Location
    San Diego, CA
    MS-Off Ver
    Excel for 365
    Posts
    62

    Re: Consolidate Repetitive Macros using Variable and loop

    Thanks Jeff, and thanks for the link to declaring variables. As I'm sure you can tell im still at the frankenmacro stage

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Consolidate Repetitive Macros using Variable and loop

    Hey, good start.

+ 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] Consolidate repetitive code - (populating two comboboxes from an advanced filter)
    By melpa in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-22-2019, 09:06 AM
  2. VBA/Macros - sorting across multiple repetitive columns
    By almugs in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-29-2014, 05:48 PM
  3. Loop to shorten repetitive and long code?
    By humboldtguy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-16-2013, 03:29 AM
  4. Consolidate Repetitive Data
    By arasan25 in forum Excel General
    Replies: 13
    Last Post: 02-13-2012, 05:18 AM
  5. Loop for repetitive code
    By jackandjill in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-18-2010, 10:18 PM
  6. repetitive macros-solved
    By henrysmith in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-06-2009, 12:48 PM
  7. Convert repetitive IF statements to array loop?
    By bntringa in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-27-2006, 05:45 PM

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