LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search excel file, return value from different column

Solved!
Go to solution

I've tried searching the Excel board and this board, but haven't found anything that can help yet. I have an Excel file that has three columns. I want to search the first column for a value (1-99), then return the value from the same row, but from the 3rd column. Pretty much the same as the VLookup function, but I haven't found a way to do it in LV. Here's a basic example:

 

Column1 | Column 2 | Column 3

01              PSIG         3

.

.

20              PSIS         2

 

 

So, if "20" is entered, it will return the value "2".

 

Thanks again

0 Kudos
Message 1 of 12
(4,284 Views)

I was able to find a small VI that finds the address of the value that I'm looking for. For example, if I search for "05" it will tell me the column and row it's in. However, I want it to return the value that is in the same row, but different column. I'm not sure which ActiveX control to use for this.

 

Here's an image of the VI:

 

Excel.jpg

0 Kudos
Message 2 of 12
(4,270 Views)
Solution
Accepted by topic author buickgn

@buickgn wrote:

 Pretty much the same as the VLookup function, but I haven't found a way to do it in LV. 

Thanks again



Well, use the VLookup function then, from _Application WorksheetFunction (pass a range reference to Argument 2).

 

Ben64

 

use of VLookup.png

Message 3 of 12
(4,264 Views)

Hi Ben64,

 

Is it possible to do this using a different function? For example, in the screenshot I posted it requires only one input, "what" to find. I don't want the user to have to input anything else if at all possible. Would it be a better idea to not use an Excel file and use a CSV file?

0 Kudos
Message 4 of 12
(4,256 Views)

@buickgn wrote:

Hi Ben64,

 

Is it possible to do this using a different function? For example, in the screenshot I posted it requires only one input, "what" to find. I don't want the user to have to input anything else if at all possible. Would it be a better idea to not use an Excel file and use a CSV file?


Why use a different function if VLookup do exactly what you want? You can show / hide or change to constant anything you want, leave it to the user to enter a value in the look for control only.

 

Ben64

0 Kudos
Message 5 of 12
(4,252 Views)

Is it possible to use the Application WorksheetFunction in place of the two "Range" invoke nodes in my screenshot? If so, what do you have the Application WorksheetFunction's "reference" wired to? Sorry, I'm still not sure how to wire this to get the result.

0 Kudos
Message 6 of 12
(4,248 Views)

Is there an Application reference output to the Open Excel vi you're using. If yes use it for the _Application WorksheetFunction reference. Also, the reference should be closed in the reverse order they were opened. You should change this at the end of the vi picture you are showing. (no you can't use the Application WorksheetFunction in place of the two "Range" invoke nodes in your screenshot)

 

Ben64

0 Kudos
Message 7 of 12
(4,243 Views)

There is an Application reference output. If I can't use the Application WorksheetFunction in place of the two "Range" invoke nodes, where do you put the code in your picture? Is it possible to post the code in your picture so I can modify the controls with constants as needed?

0 Kudos
Message 8 of 12
(4,236 Views)

Look For is what you are looking for in the first column, you can change the string control to a numeric control if you are looking for a numeric value. Column is the column number of the value you want to output (column A -> 1, column B -> 2, ...). Replace range_lookup by a boolean False constant.

 

Ben64

0 Kudos
Message 9 of 12
(4,222 Views)

Here is what I have now. It works and gives me the correct value. However, after it runs it seems to be holding the file in memory and it only opens in read-only. How can I make this release the file?

 

Excel.jpg

0 Kudos
Message 10 of 12
(4,219 Views)