Thursday, July 8, 2010

How to according to a cell value in the Sheet2 to find values in the matching row in the Sheet1

Software Environment
Version:4.0.2
Edition:Excel

Effect image

Example code

$Address_Sheet2$="A2"
<SelectRange($Address_Sheet2$,"Sheet2","Book1.xls")>
$ID_Sheet2$=<ReadCell()>

For(10)
$Address_Sheet1$="A2"
$ID_Sheet1$=<ReadCell($Address_Sheet1$,"Sheet1")>
While($ID_Sheet2$,"<>",$ID_Sheet1$)
$Address_Sheet1$=<RowAddress($Address_Sheet1$)>
$ID_Sheet1$=<ReadCell($Address_Sheet1$,"Sheet1")>
WEnd
$Address_Sheet1$=<ColumnAddress($Address_Sheet1$)>
$Name$=<ReadCell($Address_Sheet1$,"Sheet1")>

$Address_Sheet2$=<ColumnAddress($Address_Sheet2$)>
<WriteCell($Name$,$Address_Sheet2$,"Sheet2")>
$Address_Sheet2$=<ColumnAddress($Address_Sheet2$,"Left")>
$Address_Sheet2$=<RowAddress($Address_Sheet2$)>
$ID_Sheet2$=<ReadCell($Address_Sheet2$,"Sheet2")>
Next


Code explanation
$Address_Sheet2$; Save cell address in the sheet2.

$ID_Sheet2$; Save ID value in the sheet2.

$Address_Sheet1$; Save cell address in the sheet1.

$ID_Sheet1$; Save ID value in the sheet1.

$Name$; Save the matching Name value in the sheet1.

$ID_Sheet2$=<ReadCell()>; Get a value from the cell selected by cursor.

$ID_Sheet1$=<ReadCell($Address_Sheet1$,"Sheet1")>; Get a value from the specified cell address in the active workbook.

While($ID_Sheet2$,"<>",$ID_Sheet1$); Comparing the two values until equal.