+ Reply to Thread
Results 1 to 14 of 14

How do I get this Function to Work in G-Docs

  1. #1
    Registered User
    Join Date
    05-29-2012
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    31

    How do I get this Function to Work in G-Docs

    Please help! need to get this formula to work on google docs.

    Got some great help in getting an excel formula that references cell B1 with a list of names on A1:A833 .

    Entered The following into module 1:

    Please Login or Register  to view this content.

    Entered :
    =getnames(B1,A1:A833)

    into cell 3. and it works great! But I can't upload it to googledocs with the macros enabled. Anyone know how to enter this into to google or have a formula that does something similar?

    Excel sheet attached. THANK YOU SO MUCH!

    Copy of wuzwrong-2.xlsm
    Last edited by jeffreybrown; 07-12-2013 at 10:11 AM. Reason: As per Forum Rule #3, please use code tags…Thanks.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,814

    Re: How do I get this Function to Work in G-Docs

    Perhaps this will help https://developers.google.com/apps-s...stom_functions

    Note that visual basic is not the language google docs uses. It appears that google docs spreadsheets use Javascript as the macro language for custom functions. I personally am not at all familiar with Javascript. In the end, it should be as easy as converting your VBA code to javascript, then putting it into GoogleDocs.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: How do I get this Function to Work in G-Docs

    Literal translation

    PHP Code: 
    function getNames(sPararange) {
        var 
    getNamesTemp ",";
        for (var 
    0range.lengthi++) {
            for (var 
    0range[0].lengthj++) {
                var 
    currentValue range[i][j];
                if (
    currentValue.length 0) {
                    
    Name currentValue.toString().split(",")[0].replace(/^\s+|\s+$/g'');
                    if (
    sPara.indexOf(Name) >= && getNamesTemp.indexOf("," Name ",") === -1) {
                        
    getNamesTemp += Name ",";
                    }
                }
            }
        }
        return 
    getNamesTemp.slice(1getNamesTemp.length 1);


  4. #4
    Registered User
    Join Date
    05-29-2012
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: How do I get this Function to Work in G-Docs

    Really Appreciate the Translation! I'm having trouble getting it to work on Google Docs though. I entered it into script editor and hit run. Error returned : "TypeError: Cannot read property "length" from undefined. (line 3, file "GetNames")"

    Line three referring to : " for (var i = 0; i < range.length; i++) { "

    Are you able to get the code to run on a google spreadsheet?

    Once again I am new to this and I really appreciate the help!

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: How do I get this Function to Work in G-Docs

    Yes, what did your formula look like?

  6. #6
    Registered User
    Join Date
    05-29-2012
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: How do I get this Function to Work in G-Docs

    Quote Originally Posted by Kyle123 View Post
    Yes, what did your formula look like?
    I am plugging in the formula to Google Docs Script editor. The formula translation you provided above :


    Please Login or Register  to view this content.
    function getNames(sPara, range) {
    var getNamesTemp = ",";
    for (var i = 0; i < range.length; i++) {
    for (var j = 0; j < range[0].length; j++) {
    var currentValue = range[i][j];
    if (currentValue.length > 0) {
    Name = currentValue.toString().split(",")[0].replace(/^s+|s+$/g, '');
    if (sPara.indexOf(Name) >= 0 && getNamesTemp.indexOf("," + Name + ",") === -1) {
    getNamesTemp += Name + ",";
    }
    }
    }
    }
    return getNamesTemp.slice(1, getNamesTemp.length - 1);
    }
    Please Login or Register  to view this content.
    When I plug this into script editor on google spreadsheets, it says there is a problem with line three. I had my java-script-savvy friend and take a look to see if he could get it to run on google spreadsheets script editor but no luck.

    I am trying to get the following excel formula to work in google docs.

    Copy of wuzwrong-2.xlsm

    It reads the paragraph in B1 and references it with A:A and provides the matches in Column C1. Works great on Excel but I can't figure how to get it to work on Gdocs. If there is even another method you would suggest I would be open to that. Just figured this was the easiest avenue.

    Thanks again for all the Help!

  7. #7
    Registered User
    Join Date
    05-29-2012
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: How do I get this Function to Work in G-Docs

    Just to clarify:
    To Immitate what I am doing :
    open up docs.google.com
    open a new spreadsheet
    Open tools tab
    select script editor
    enter the code and press the play button.


    If the code is recognized, I hope, googledocs will do the same thing I have been able to get excel to do

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How do I get this Function to Work in G-Docs

    Have you saved the project you've pasted the script into?
    If posting code please use code tags, see here.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How do I get this Function to Work in G-Docs

    Why would you run a function that's supposed to be used on a worksheet?

    The reason you get the error on line 3 is because no arguments have been passed to the function when you do that.

  10. #10
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: How do I get this Function to Work in G-Docs

    Thanks Norie - that's why I asked what his function looked like

  11. #11
    Registered User
    Join Date
    05-29-2012
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: How do I get this Function to Work in G-Docs

    Fundamental error on my part. That is great. I may need to tweek just one or two things but this is a real step forward for my efforts. Thanks so much you guys!

  12. #12
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: How do I get this Function to Work in G-Docs

    Is suspect that:
    PHP Code: 
    function getNames(sPararange) { 
        for (var 
    0range.lengthi++) { 
            for (var 
    0range[0].lengthj++) { 
                var 
    currentValue range[i][j]; 
                if (
    currentValue.length 0) { 
                    var 
    Name currentValue.toString().split(",")[0].trim(); 
                    if (
    sPara.indexOf(Name) >= 0) { 
                        return 
    sPara;
                    } 
                } 
            } 
        } 

    Is somewhat more efficient

  13. #13
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: How do I get this Function to Work in G-Docs

    Or for IE8 support - I'm guessing here that Google doesn't do any sort of fancy function replacement where functions are not supported by the browser in use:
    PHP Code: 
    function getNames(sPararange) { 
        for (var 
    0range.lengthi++) { 
            for (var 
    0range[0].lengthj++) { 
                var 
    currentValue range[i][j]; 
                if (
    currentValue.length 0) { 
                    var 
    Name currentValue.toString().replace(/^\s\s*/, '').replace(/\s\s*$/, ''); 
                    if (
    sPara.indexOf(Name) >= 0) { 
                        return 
    sPara;
                    } 
                } 
            } 
        } 

    Last edited by Kyle123; 07-15-2013 at 11:35 AM.

  14. #14
    Registered User
    Join Date
    05-29-2012
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: How do I get this Function to Work in G-Docs

    I punched in the new code, it just repeats what in in Cell B and enters the entire paragraph into cell C. thanks though!

    I don't suppose you know how I would tweek it so that only the full names pop up? The formula is referencing words like "Police" with the name "Napolitano" and is returning the word "Poli" . I suppose I could just go through and put in a code that says don't include "poli" and do that for any other problems that arrise but is there a way for the code to only recognize "Napolitano" in it's entirety or when it is the smallest part of a whole word?

    for example :

    can I have it not recognize 'Police' and 'Napolitano' as 'poli' but still have it recognize 'Napolitano' when it is a smaller part of a larger word like "Napolitano!" or "Napolitano." ?
    Last edited by fansoffloyd; 07-15-2013 at 12:26 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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