0

I want to ask, how about the code in writing VBA Excel like this.

Textbox1=Application.WorksheetFunction.Index(dataname, Application.WorksheetFunction.Match(SpinButton1.Value, indexdataname, 0), 3)

In simple formulas on sheets like

=INDEX(dataname,MATCH(number,indexdataname,0),3)
2
  • 3
    What is indexdataname? It is not defined. Same with dataname. Please show a minimal reproducible example. Commented Jul 31, 2019 at 11:33
  • dataname and indexdataname from define name. dataname A1: C15, indexdataname A1: A15 Commented Jul 31, 2019 at 11:36

1 Answer 1

1

I assume indexdataname and dataname are named ranges.

It would work with something like below:

Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1") 'define sheet name

Dim Dataname As Range
Set Dataname = ws.Range("dataname")

Dim IndexDataname As Range
Set IndexDataname = ws.Range("indexdataname")

Dim MatchedRow As Double
On Error Resume Next 'next line throws error if no match is found
MatchedRow = Application.WorksheetFunction.Match(SpinButton1.Value, IndexDataname, 0)
On Error Goto 0 'always re-activate error reporting !!!

'test if something matched
If MatchedRow = 0 Then
    MsgBox "Nothing matched", vbCritical
    Exit Sub
End If

Textbox1 = Application.WorksheetFunction.Index(Dataname, MatchedRow, 9)
Sign up to request clarification or add additional context in comments.

1 Comment

Your explanation is very perfect, complete with comments and very helpful for me who is still a layman studying excel. Once again, thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.