+ Reply to Thread
Results 1 to 8 of 8

Repeating Code Between Google Sheets Macros

  1. #1
    Registered User
    Join Date
    08-21-2012
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    8

    Repeating Code Between Google Sheets Macros

    I have two macros. One called Desktop and one called Harddrive.

    For the Desktop macro it will put the word Desktop on Cell A3

    It will then copy parts from the sheet and paste it in another sheet.

    For the Harddrive macro it will put the word Harddrive on Cell A3

    It will then copy parts from the sheet and paste it in another sheet.

    When I am wondering is, since the code for copying and pasting the information is the exact same, is there a way I can have the code in 1 spot then recall it into the macro.

    I know there is a way to do this in programming but I forget the name of it.

    What I would like is:

    CopyCode
    Instructions for copying what I want

    Desktop Macro
    Put word Desktop in A3
    Run CopyCode

    Harddrive Macro
    Put work Harddrive in A3
    Run CopyCode

    I would like this so if I need to make a change to the copying code, I just need to update the one spot
    Last edited by 6StringJazzer; 05-23-2021 at 09:10 AM. Reason: Moved from Excel Programming / VBA / Macros

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Repeating Code Between Macros

    Something like this.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-21-2012
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Repeating Code Between Macros

    In the macro code it has the sections called function.. here is most of the code (removed some to make easier to shorter to post)

    --This is the stuff I want to be different in each

    In the HarddriveList Marco
    spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Info'), true);
    spreadsheet.getRange('B1').activate();
    spreadsheet.getCurrentCell().setValue('Harddrive');

    In the Desktoplist Macro
    spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Info'), true);
    spreadsheet.getRange('B1').activate();
    spreadsheet.getCurrentCell().setValue('Harddrive');


    Here is an the current macro code I would like to be able to use in each

    function HarddriveList() {

    spreadsheet.getRange('f4:AB353').activate();
    spreadsheet.getRange('f3:AB3').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);

    };

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Repeating Code Between Macros

    This is a VBA forum, so no idea about what you are talking about.

  5. #5
    Registered User
    Join Date
    08-21-2012
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Repeating Code Between Macros

    Sorry. I saw a marco section and thought this was the place for it. Because I thought was was VBA code.

  6. #6
    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: Repeating Code Between Macros

    This looks like a Google sheets macro to me. Are you using Excel or something else?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  7. #7
    Registered User
    Join Date
    08-21-2012
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Repeating Code Between Macros

    Google sheets. I have used this site a few times for help in stuff I was doing in sheets and open office

  8. #8
    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: Repeating Code Between Google Sheets Macros

    It is not VBA. It is the language used for Google Sheets macros, which is not applicable to Excel. I've moved your thread to the appropriate subforum.

+ 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. Repeating Automatic Dating Macros
    By sugiharg in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-25-2013, 05:23 PM
  2. Repeating Macros w/in the same spreadsheet
    By S Larkin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-21-2012, 01:42 PM
  3. Repeating macros
    By Stryper in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-24-2011, 10:11 AM
  4. Repeating Macros
    By Marcus2526 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2010, 12:55 PM
  5. Repeating code
    By Bob316 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-24-2010, 03:00 AM
  6. Help with repeating the code
    By rusoo7 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-23-2009, 07:05 AM
  7. Repeating code
    By Myrmecophaga in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-31-2008, 06:57 AM
  8. Repeating code
    By mandeepuppal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-18-2006, 06:50 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