Is Find API has bugs?


Why did I start with C3 and find B2
how to use find api , the result is not my Expected

I confirm some unexpected behaviors with “RangeApi.Find”; either good result, either wrong result, and not stable results with a second call :frowning:

Hello @yuhui and @jpp
As far as I can see, the provided screenshots are related to our web-site. Please provide me with the link to this sample.
If you used your own samples, please provide me with script itself and a test file. We will check out the situation.

Hello @Alexandre
I can not share my working sample because of confidential data.
But far away in my investigations I found the root cause of the bug:
Find is a method of RangeApi. So it Should works inside the given range. It does not ! In fact it run inside a range of the current sheet.
my work around : a call to oRange.GetWorksheet().SetActive() and then the oRange.Find(…) call is well working !

var oWorksheet = Api.GetActiveSheet();
oWorksheet.GetRange(“B1”).SetValue(2014);
oWorksheet.GetRange(“C1”).SetValue(2015);
oWorksheet.GetRange(“D1”).SetValue(2016);
oWorksheet.GetRange(“A2”).SetValue(“Projected Revenue”);
oWorksheet.GetRange(“A3”).SetValue(“Estimated Costs”);
oWorksheet.GetRange(“A4”).SetValue(“Cost price”);
oWorksheet.GetRange(“B2”).SetValue(200);
oWorksheet.GetRange(“B3”).SetValue(250);
oWorksheet.GetRange(“B4”).SetValue(50);
oWorksheet.GetRange(“C2”).SetValue(200);
oWorksheet.GetRange(“C3”).SetValue(260);
oWorksheet.GetRange(“C4”).SetValue(120);
oWorksheet.GetRange(“D2”).SetValue(200);
oWorksheet.GetRange(“D3”).SetValue(200);
oWorksheet.GetRange(“D4”).SetValue(160);
var oRange = oWorksheet.GetRange(“A2:D4”);
var oSearchRange = oRange.Find(“200”, “C3”, “xlValues”, “xlWhole”, “xlByColumns”, “xlNext”, true);
oSearchRange.SetFillColor(Api.CreateColorFromRGB(255, 213, 191));

you can try the code

Thank you, we are checking the situation.

Hello @yuhui
Sorry for the late reply.
We have checked provided code it seems it works as expected. Your code tries to find value 200 in the C3 cell, but there’s no such value so it moves to another cell. You can change the Find request (change value of search to 260) to achieve the desired result:

(function() {
var oWorksheet = Api.GetActiveSheet();
oWorksheet.GetRange("B1").SetValue(2014);
oWorksheet.GetRange("C1").SetValue(2015);
oWorksheet.GetRange("D1").SetValue(2016);
oWorksheet.GetRange("A2").SetValue("Projected Revenue");
oWorksheet.GetRange("A3").SetValue("Estimated Costs");
oWorksheet.GetRange("A4").SetValue("Cost price");
oWorksheet.GetRange("B2").SetValue(200);
oWorksheet.GetRange("B3").SetValue(250);
oWorksheet.GetRange("B4").SetValue(50);
oWorksheet.GetRange("C2").SetValue(200);
oWorksheet.GetRange("C3").SetValue(260);
oWorksheet.GetRange("C4").SetValue(120);
oWorksheet.GetRange("D2").SetValue(200);
oWorksheet.GetRange("D3").SetValue(200);
oWorksheet.GetRange("D4").SetValue(160);
var oRange = oWorksheet.GetRange("A2:D4");
var oSearchRange = oRange.Find("260", "C3", "xlValues", "xlWhole", "xlByColumns", "xlNext", true);
oSearchRange.SetFillColor(Api.CreateColorFromRGB(255, 213, 191));
})();

Please let us know if it resolves the situation or if we misunderstood your request.