Get random cell from excel?

I was wanting to know if this is possible.

I want my bot to read a CSV, and return with one of the items it finds in column B, based on the product it was fed from the process.

EG:

If Product 1 was seen, return any 1 of the cells from column B, next to Product 1.
If Product 2 was seen, return any 1 of the cells from column B, next to Product 2.
If Product 3 was seen, return any 1 of the cells from column B, next to Product 3.

image

1 Like
  1. Read CSV into Data Table.
  2. Filter the rows based on the Product Type. For example you fed the Product 1 (you can store it in a variable to work with any product type.)

strProductType = “Product 1”

Assign Activity, filteredDataTable = yourDataTable.Select("Type='" + strProductType + "'").CopyToDataTable

Assign Activity, numberOfRows = filteredDataTable.Rows.Count

  1. Get the random value from Column FAB

Declare one variable of type System.Random and assign the default value like below -
variable name: rnd
type: System.Random
default value: New System.Random()

If numberOfRows > 0

Assign Activity, strRandomFAB = filteredDataTable.Rows(rnd.Next(0,numberOfRows)).Item("FAB").ToString

End If

Every time you run this program, it takes different random value from Column B for the given Product Type.

Regards,
Karthik Byggari

4 Likes

This is perfect AND amazing!!! Thank you!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.