LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Excel_RangeFind(Next) ?

For my project I need to search an excel sheet and find which cells contains the text '###START'.

Off course I can search every cell in the sheet with two for-loops, one for column and one for the row,

I think it should be quicker to use the Excel_RangeFind and Excel_RangeFindNext functions.

 

I created the following code (removed the error handling for readability reasons)

 

// Get Active Workbook Sheets
Excel_GetProperty (ExcelAppHandle, NULL, Excel_AppSheets, CAVT_OBJHANDLE, &ExcelSheetsHandle);
// Get Sheet by index
Excel_SheetsItem (ExcelSheetsHandle, NULL, CA_VariantInt(sheetIndex), &ExcelWorksheetHandle);
// Make Sheet Active
Excel_WorksheetActivate (ExcelWorksheetHandle, NULL);

CA_VariantSetCString (&MyVariant, "###START");
// Set Range to Sheet
CA_VariantSetCString (&MyCellRangeV, "A1:IU65536");
Excel_WorksheetRange (ExcelWorksheetHandle, NULL, MyCellRangeV, CA_DEFAULT_VAL, &ExcelRangeHandle);
Excel_RangeActivate (ExcelRangeHandle, &ErrorInfo, NULL);

Excel_RangeFind (ExcelRangeHandle, NULL, MyVariant, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
CA_DEFAULT_VAL, CA_VariantInt(ExcelConst_xlByRows), ExcelConst_xlNext,
CA_DEFAULT_VAL, CA_DEFAULT_VAL, &FoundRangeHandle);
Excel_RangeAddress (FoundRangeHandle, NULL, CA_DEFAULT_VAL, CA_DEFAULT_VAL, ExcelConst_xlA1, CA_DEFAULT_VAL, CA_DEFAULT_VAL, &ptr);

while (...)
{
   status = Excel_RangeFindNext (FoundRangeHandle, NULL, CA_DEFAULT_VAL, &FoundRangeHandle);
}

Problem with this code is that it is only finding the first field which contains '###START'.

I am using the excel2000.fp and Excel2010 with Labwindows/CVI 9.0.

 

Does someone has experience with the RangeFind functions ?

 

Thanks for helping, Patrick


0 Kudos
Message 1 of 4
(3,377 Views)

Hi,

Are you based on the example of using Excel (excel2000dem). You select a range and you read, then you do your search. Really I have not used this function, but it seems to me that you must use the same principle.

Thanks

0 Kudos
Message 2 of 4
(3,372 Views)

Hello,

 

I think that you have to look at the links below. They could be useful.

http://www.cpearson.com/Excel/FindAll.aspx

http://excel.bigresource.com/-range-find-need-to-return-cell-address-DQfGFsOA.html

 

Regards,

 

 

0 Kudos
Message 3 of 4
(3,349 Views)

Hi,

Thanks for the links. I will try these when I am back from my current trip to Romania.

 

Regards

0 Kudos
Message 4 of 4
(3,347 Views)