+ Reply to Thread
Results 1 to 10 of 10

Code shortening

  1. #1
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Code shortening

    Can the code below be made shorter?
    I mean, instead of the repeating "copy/paste", is there another shorter way?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Code shortening

    Hi,

    You could use a separate routine for the copy and paste
    Please Login or Register  to view this content.
    and then the code you posted would become
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Code shortening

    Please Login or Register  to view this content.
    So in essence, when I execute macro "test", it would call the subroutine "CopyPasteValueAndFormat"?
    And both can be in the same module?

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Code shortening

    Yes, that's correct.

  5. #5
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Code shortening

    Ok. Got it. Thanks!

    And, I suppose, if I do this many times, I can set up several subroutines (CopyPasteValueAndFormat1, CopyPasteValueAndFormat2, etc) and specify in my macro which one to use.

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Code shortening

    Yes you can. You may even be able to have one routine but use a few more parameters (e.g. the sheet to copy to) to make it more generic.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,972

    Re: Code shortening

    Do the columns all have the same number of rows of data? If so, you could just determine the last row once and use that.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  8. #8
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Code shortening

    Not sure what you are asking but we are taking a total of 7 cells here and there and paste them in last row of columns 28 through 34.
    And yes, the last empty row for any column in 28-34 is the last row for all of them. In other words, the pasted data will be in one row.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,972

    Re: Code shortening

    Just for fun:

    Please Login or Register  to view this content.

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,972

    Re: Code shortening

    Less distracting:

    Please Login or Register  to view this content.

+ 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. Shortening the code...?
    By excellenthelp in forum Excel General
    Replies: 17
    Last Post: 02-24-2016, 04:20 PM
  2. [SOLVED] Shortening of VBA code
    By PDBartlett in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-15-2014, 07:10 AM
  3. Shortening Code
    By ScabbyDog in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-01-2012, 11:53 AM
  4. Need help shortening code
    By kainis2k in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-11-2012, 01:01 PM
  5. Shortening up Code
    By Kr4ftw3rk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-11-2008, 11:38 AM
  6. Shortening Code
    By T De Villiers in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-20-2007, 11:46 AM
  7. Shortening Code
    By T De Villiers in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-20-2007, 11:17 AM

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