min7b5_b9_b11_b13
min7b5_b9_b11_b13

Reputation: 157

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

Upvotes: 12

Views: 52193

Answers (2)

Ed Nelson
Ed Nelson

Reputation: 10259

You can do this with a formula and copy down:

 ="Hi "& B4 &", I'm reaching out to you today..."

Upvotes: 23

Cooper
Cooper

Reputation: 64100

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

Upvotes: 1

Related Questions