Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grabbing text from a cell to use in a sentence in another cell - Google Sheets

On Google Sheets, I'm trying to use the text in one cell (say B4 contains: "Janet") and reference it in a sentence in another cell (say G4 is: "Hi {Enter B4 here}, I'm reaching out to you today...")

A little background: I have about 130 columns of data that contain websites, first name, email, and vendor type that I hope to reference in an out reach email that I just copy down across a series of columns.

Thanks for any help

like image 346
min7b5_b9_b11_b13 Avatar asked Jul 26 '17 20:07

min7b5_b9_b11_b13


People also ask

How do I extract part of a text string from a cell in Google Sheets?

You can use LEFT + SEARCH in Google Sheets to extract text from a string or to extract data that comes before a specific text. LEFT is used to return a specific number of characters from the leftmost cell's beginning. SEARCH looks for specific characters/strings and determines their position.

How do I pull text from a cell in sheets?

You can extract text from the left side of a cell in Excel by using the LEFT Function. Simply supply the text, and enter the number of characters to return.


2 Answers

You can do this with a formula and copy down:

 ="Hi "& B4 &", I'm reaching out to you today..."
like image 86
Ed Nelson Avatar answered Oct 09 '22 16:10

Ed Nelson


Not sure if this is entirely what you want but this will do a replacement. It looks for a structure like this {{A2}} with a cell in A1Notation in the center. You must selected the cell with the text that you want to perform the replacement in.

function mergeReplace() 
{
  var re=/\{\{[A-Z]{1,2}\d{1,3}\}\}/g;  
  var ss=SpreadsheetApp.getActive();
  var sht=ss.getSheetByName('Matches');
  var rng=sht.getActiveRange();
  var a1=rng.getA1Notation();
  var s=rng.getValue();
  var matches=s.match(re);
  for(var i=0;i<matches.length;i++)
  {
    var r=matches[i].slice(2,-2);
    s=s.replace(matches[i],sht.getRange(r).getValue());
  }
  rng.setValue(s);
}

Here's what my data looked like:

Before Replacement:

enter image description here

After Replacement:

enter image description here

like image 24
Cooper Avatar answered Oct 09 '22 18:10

Cooper