I have a column that contains a text like this on each row (text is different) - ABC1 London - ACompany: Ground Floor, Main Tower, 127 Bridge Street, London AB1 1JZ.
The script I have extracted the city name from that text and store it into a new array.
When I try to write those values into a new column I get Cannot convert Array to Object[][]. (line 18, file "Code").
I have tried to loop through that array again, but it returns 101 arrays (I have 101 rows) so when I set cities[0].length as width it pastes it on 101 column.
All I need is to get the city name from the text and paste it on the same sheet to a different column - Ex. the text is on column B12 and I want to paste just the city name into R12 - hope it makes sense.
Please see below the code I have
function getCity() {
var ss = SpreadsheetApp.openById('ID');
var sh = ss.getSheetByName('Response Data');
var range = sh.getDataRange();
var values = range.getValues();
var cities = [];
var newCity = []
for (var i=1;i<values.length;i++)
{
var cellText = values[i][11];
if(typeof cellText === 'number') {continue;};
cities.push(cellText.substring(5, (cellText + " -").indexOf("-") - 1));
}
Logger.log(cities);
sh.getRange(2, 18, cities.length, 1).setValues(cities);
}
Thank you!