B4J Question Excel Vlookup & Index Match Function

h.drose

Member
Hi,

There is any way to use Vlookup and Index - Match Functions on BJ4?

On Visual basic must be like this:

example: Application.WorksheetFunction.Vlookup(x, Sheet3.Range("C:AZ"), 39, 0)

I want do the same, how can I do this?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Get the data with XLReader and do whatever you like programmatically.

1631082015079.png


B4X:
Dim ReaderResult As XLReaderResult = XL.Reader.ReadSheetByIndex(File.DirAssets, "Countries of the world.xlsx", 0)
Dim range As XLRange = XL.CreateXLRange(XL.AddressName("B6"), XL.AddressName("C232"))
Dim address As XLAddress = FindValueInRange(ReaderResult, range, "Zambia")
If address.IsInitialized Then
    Log($"Population: $1.0{ReaderResult.Get(XL.AddressOne("D", address.Row0Based + 1))}"$)
End If

B4X:
Private Sub FindValueInRange (ReaderResult As XLReaderResult, Range As XLRange, Value As String) As XLAddress
    For c = Range.FirstAddress.Col0Based To Range.SecondAddress.Col0Based
        For r = Range.FirstAddress.Row0Based To Range.SecondAddress.Row0Based
            Dim address As XLAddress = XL.AddressZero(c, r)
            Dim v As String = ReaderResult.Get(address).As(String).Trim 'remove whitespace
            If v = Value Then Return address
        Next
    Next
    Dim a As XLAddress
    Return a 'uninitialized
End Sub

 
Upvote 0
Top