+ Reply to Thread
Results 1 to 4 of 4

Office Script to convert formulas to values

  1. #1
    Registered User
    Join Date
    08-17-2024
    Location
    England
    MS-Off Ver
    MS 365 Version 2407
    Posts
    1

    Office Script to convert formulas to values

    Cross-posted at https://stackoverflow.com/questions/...nerates-answer --6SJ

    Hi

    I'm trying to create a form which generates a unique ID which doesn't change, for each row/item.

    To do this I am going to use a formula to generate a unique ID but to prevent it from changing later, I would like to create a macro which copies and pastes the cell contents as a value, to remove the formula, once the cell value has been generated. HOWEVER, I want the copy and paste to only work on cells in the column which have a value that isn't blank (e.g., so for empty columns which may be filled later, the formula doesn't get removed).

    So far I have

    Please Login or Register  to view this content.
    Which copies and pastes the whole table column, but I'm unsure how to add in the 'IF' statement (so if the value is not blank, then do it, if the value is blank, do not copy paste as value).

    Would anyone be able to help me write this? Apologies, it's been a really long time since I last dabbled in VBA.

    Equally, if you have a better way of generating a unique ID that doesn't change per row, that isn't a manual task, please let me know!
    Last edited by 6StringJazzer; 08-19-2024 at 11:47 AM.

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

    Re: Writing macro to copy paste any formulas which have generated values from column

    Welcome to the Forum excellearner167 !

    Please review our guidelines, which recommend code tags for code. I have added them because it's your first post.

    Also note that this code is not VBA, it is Office Script. Therefore I have updated your title to clarify it.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: Office Script to convert formulas to values

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not told us about this. You are required to do so. Cross-posts are allowed but you must provide a link to your posts on other sites.

    Please see Forum Rule #7 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important: https://excelguru.ca/a-message-to-forum-cross-posters/

    I have added the link because you are a new member. Please notify us if you have posted the same question anywhere else.

  4. #4
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,093

    Re: Office Script to convert formulas to values

    Does this work for you?

    PHP Code: 
    function main(workbookExcelScript.Workbook) {
        
    let selectedSheet workbook.getActiveWorksheet();
        
    // Paste to range B10:B109 on selectedSheet from range B10:B109 on selectedSheet

        
    let xselectedSheet.getRange("B10:B109").getSpecialCells(ExcelScript.SpecialCellType.formulas);
        if (
    == undefined){
            
    console.log("No formulas");
            return;
        }
        
    let rng selectedSheet.getRange(x.getAddress());
        
    let rMax rng.getRowCount();    
        
    let vals rng.getValues()
        for (
    let r=0rMaxr++){            
            if (
    vals[r][0] !== "") {
                var 
    rng.getCell(r0);
                
    c.setValue(vals[r][0]);
            }
        }

    Last edited by ByteMarks; 08-19-2024 at 12:29 PM.

+ 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. Help writing a VBA Macro to copy formulas and values to another sheet
    By JN831 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-04-2023, 12:30 AM
  2. [SOLVED] Help writing macro to copy specific columns and paste them into other column
    By jsuar123 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-30-2019, 12:34 PM
  3. Macro Copy Paste values not formulas lines above 0
    By bast0504 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-06-2013, 01:30 PM
  4. Vba - find next empty column, insert column, copy paste values & copy paste formulas
    By DoodlesMama in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2012, 12:43 PM
  5. macro to copy cells with formulas and paste them as values
    By sammi8796 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-25-2012, 08:00 PM
  6. VBA to copy formulas in column D and paste as values in same column
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-10-2012, 05:18 AM
  7. Macro to Copy Paste Values and Formulas
    By thillis in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-19-2009, 11:55 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