Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8832399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:31:11+00:00 2026-06-14T08:31:11+00:00

This is a little different than my last question, but am unable to transfer

  • 0

This is a little different than my last question, but am unable to transfer the code for that to this.

Sheet 1 has individual contacts with company name. Each individual has one name, but company name may show up several times based on how many individuals in the sheet. So:

Name        Company       Work Address
John Smith  ABC Company
Jim Smith   XYZ Company
Bob Smith   ABC Company

Sheet 2 has Companies with their work address:

Company        Work Address
ABC Company    1234 Street, USA
XYZ Company    5678 Street, USA

How do I script so that the company addresses go over to the individual contact sheet?

I’ve tried using arrays, and searching for row/col indexes, but I am missing something. This code has got me the closest, but can’t quite make it work (The code column and row numbers don’t match with the sample, they are just the current arrays I am trying to work on, fyi):

function populateCofieldsincontact() {
  var writeSheet = sskey.getSheetByName('POCs');
  var sourceSheet = sskey.getSheetByName('Businesses');

  var writeData = writeSheet.getRange(1, 6, writeSheet.getLastRow(), 5).getValues();Logger.log(writeData)
  for (var w = 0; w < writeData.length; w++ ) {

    var sourceData = sourceSheet.getRange(1, 2, sourceSheet.getLastRow(), 3).getValues();
    var dest = [];
    for (var i = 0; i < sourceData.length; i++ ) {
      if (writeData ==sourceData[i][0].toString().match(writeData)) {
        dest.push(sourceData[i][2]); 
      }
    }
  }
  if (dest.length > 0 ) {
      writeSheet.getRange(2,10,dest.length,1).setValue(dest.toString());
    }
}

Any help greatly appreciated!

quick update – I am able to get the setValue (not setValues that won’t work for some reason) and write the addresses in the correct column, but only way I could think to get it write in loop was to use getLastRow, and I only know how to do that for the sheet. So I wind up having all the addresses in the correct column, but written in rows starting at the bottom of where the actual data is. I can’t figure out how to get it to write into the top row, then downward, ugh.

FINAL (hopefully) Code: I inserted a [w][0] next to the second mention of writeData on line 13 of @Adam’s code and it seems to be working after a few tests. Thanks @Adam and @Serge!!:

function populateCofieldsincontact() {
  var writeSheet = sskey.getSheetByName('POCs');
  var sourceSheet = sskey.getSheetByName('Businesses');

  var writeData = writeSheet.getRange(2, 6, writeSheet.getLastRow() - 1).getValues();
  var sourceData = sourceSheet.getRange(2, 2, sourceSheet.getLastRow(), 12).getValues();
  var dest = [];
  var temp;

  for (var w = 0; w < writeData.length; w++) {
    temp = null;
    for (var i = 0; i < sourceData.length; i++) {
      if (writeData[w][0] == sourceData[i][0].toString().match(writeData[w][0])) {
        temp = sourceData[i][11];
        break;
      }
    }
    dest.push([temp]);
  }
  if (dest.length > 0 ) {
      writeSheet.getRange(2, 13, dest.length, 1).setValues(dest);  Logger.log(dest)
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:31:13+00:00Added an answer on June 14, 2026 at 8:31 am

    See if this works as expected, hopefully my assumptions are correct (edit: typo corrected as per comment):

    function populateCofieldsincontact() {
      var writeSheet = sskey.getSheetByName('POCs');
      var sourceSheet = sskey.getSheetByName('Businesses');
    
      var writeData = writeSheet.getRange(2, 6, writeSheet.getLastRow() - 1).getValues();
      var sourceData = sourceSheet.getRange(1, 2, sourceSheet.getLastRow(), 3).getValues();
      var dest = [];
      var temp;
    
      for (var w = 0; w < writeData.length; w++) {
        temp = null;
        for (var i = 0; i < sourceData.length; i++) {
          if (writeData[w][0] == sourceData[i][0].toString().match(writeData[w][0])) {
            temp = sourceData[i][2];
            break;
          }
        }
        dest.push([temp]);
      }
      if (dest.length > 0 ) {
          writeSheet.getRange(2, 10, dest.length, 1).setValues(dest);
      }
    }
    

    I guess there are a few issues with your code, but I think the important message (which took a noob like me a fair while to work out) is that when you use getValues and setValues, you are always dealing with 2-dimensional arrays, even if the array is only one column wide. Hence the square brackets in the dest.push([temp]) bit – you are actually progressively pushing an array with a length of one onto the dest array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a little different than the questions that have already been asked on
found this little code snippet that seems to do what i want, but im
This question can be little different than you expect. I am wondering how would
This question is a little different from others of a similar title. I am
I have looked at this a bunch of different ways and with what little
This little bit of syntax has been a bit of a confusion for me
I have taken this little snippet straight out of some code I'm working on:
So I got this little piece of code, don't bother the way it's implemented.
I've got some inherited code that went something like this. (Please hold the laughter...
This may seem a little more complex than you first thought when clicking on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.