How to find a similar match, not exact match

518 views
Skip to first unread message

Kevin Carrasco

unread,
Sep 7, 2020, 5:28:36 PM9/7/20
to Google Apps Script Community

I just received excellent assistance from Jean, but I noticed another change and I'm looking for suggestions/help on how to achieve this.

Current script searches for text in A:A, but looks for exact match copies all values and pastes it to top.  What would you use/think is best approach to look for a similar match.  The sheet searches for "Sup Hourly" but it doesn't pick up "Sup Hourly(X)". It would only be those tw0 and I need to copy/move both as they appear in A:A


Code:
function copyrange() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('FE'); //source sheet

  var testrange = sheet.getRange('A:A');
  var testvalue = testrange.getValues();
  var csh = ss.getSheetByName('FE'); //destination sheet

  var data = [];
  var j =[];

  //Condition check in A:A; If true copy the same row to data array
for (var i=0; i<testvalue.length; i++) {

  if ( testvalue[i] == 'Sup Hourly') {
  data.push.apply(data,sheet.getRange(i+1,1,1,60).getValues());
  //Copy matched ROW numbers to j
  j.push(i);
 }
 }
//Copy data array to destination sheet

  //Delete matched rows in source sheet
for  (var i=j.length-1; i>-1; i--) {
  sheet.deleteRow( j[i]+1 );
}

 csh.insertRows(3, j.length);
 csh.getRange(3,1,data.length,data[0].length).setValues(data);
}

 

Jean-Luc Vanhulst

unread,
Sep 7, 2020, 5:41:27 PM9/7/20
to google-apps-sc...@googlegroups.com
Kevin you can use testvalue[i].substr(1,10) == 'Sup Hourly'

What i still don't understand is what you're trying to do -  you're taking out these rows and putting them back in the same sheet?


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/3534a198-a2c8-4e54-851c-81c2e97a0b6do%40googlegroups.com.

Kevin Carrasco

unread,
Sep 7, 2020, 5:51:45 PM9/7/20
to Google Apps Script Community
Yeah, basically just moving that last block of Sups to the top of the page so they are always first!

The code returned : testvalue[i].substr is not a function
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

Jean-Luc Vanhulst

unread,
Sep 7, 2020, 6:47:05 PM9/7/20
to google-apps-sc...@googlegroups.com
To that you could simply click on Filter and sort on the first column. No code needed?

I updated the code for you. substr(0,10) (I keep forgetting 0 based while working with Sheets where the rows and columns are 1 based)
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/cf76b634-d96d-4d04-bfe0-d8ae46b6a266o%40googlegroups.com.

Kevin Carrasco

unread,
Sep 7, 2020, 7:00:17 PM9/7/20
to Google Apps Script Community
The rest are to remain as they are in time order, but it's really to grab the sup in their order and just insert them to the top of the list.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

Kevin Carrasco

unread,
Sep 7, 2020, 7:08:50 PM9/7/20
to Google Apps Script Community
Looks like the data was already sorted, so I can understand why you said that. I moved the sheet back to the version that would come over first.  Then run script to grab all sups and insert in the top spot.  While leaving all the rest in their time order.

Seems with change to 0, it' not recognizing the function still
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

Jean-Luc Vanhulst

unread,
Sep 7, 2020, 7:58:38 PM9/7/20
to google-apps-sc...@googlegroups.com
I ran it to get them to the top. But if you buy the whole script back there where a few more changes 

To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.








--


You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.


To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
--


You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.


To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.


To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/0c41832d-f2d0-4441-8416-dd495bc6a958o%40googlegroups.com.


--

Kevin Carrasco

unread,
Sep 7, 2020, 8:44:29 PM9/7/20
to Google Apps Script Community
Thank you, I see!! 


On Monday, September 7, 2020 at 5:41:27 PM UTC-4, Jean-Luc Vanhulst wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

Andrew Roberts

unread,
Sep 8, 2020, 5:04:53 AM9/8/20
to google-apps-sc...@googlegroups.com
For a "fuzzy" match check out this.

To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/1cfd819a-b77f-44de-879d-8a18ea930cceo%40googlegroups.com.

Riël Notermans

unread,
Sep 8, 2020, 5:06:54 AM9/8/20
to Google Apps Script Community
Nice, andrew.

One tool I use often is fuse.js, which also can run outside the DOM (so in GAS).
https://fusejs.io/

Met vriendelijke groet,

pic
Riël Notermans
Technisch Directeur
logo
phone
email
email
040 711 41 94
ri...@zzapps.nl
www.zzapps.nl


David Tew

unread,
Sep 8, 2020, 5:38:06 AM9/8/20
to google-apps-sc...@googlegroups.com
I use Andrew Roberts' linked to fuzzy search (https://glench.github.io/fuzzyset.js/).  It works well - with the caveat of speed (which matters when I am going through a batch of thousands).  I would have tried fuse.js to compare speed but I don't know how to install it in GAS. 
Could you point to some lines which explain how to do this Riël?  Thanks, David Tew



Riël Notermans

unread,
Sep 8, 2020, 5:39:31 AM9/8/20
to Google Apps Script Community
I requested access, I can show you and post it here.

Met vriendelijke groet,

pic
Riël Notermans
Technisch Directeur
logo
phone
email
email
040 711 41 94
ri...@zzapps.nl
www.zzapps.nl

On Tue, Sep 8, 2020 at 11:38 AM David Tew <davi...@gmail.com> wrote:
I use Andrew Roberts' linked to fuzzy search (https://glench.github.io/fuzzyset.js/).  It works well - with the caveat of speed (which matters when I am going through a batch of thousands).  I would have tried fuse.js to compare speed but I don't know how to install it in GAS. 
Could you point to some lines which explain how to do this Riël?  Thanks, David Tew



--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.

Bruce Mcpherson

unread,
Sep 8, 2020, 1:26:09 PM9/8/20
to google-apps-sc...@googlegroups.com
I published a fuzzy search that can handle stop words, stemming, umlats , stubbing etc some time ago if you want something like that.


Reply all
Reply to author
Forward
0 new messages