0

I want to create a script opening a excel workscheet, find a value in column 'A' and returns the text in column 'B' ! Using VBA in iFIX from GE ! When I want to declare 'MyValue' as range, he gives a fault message. Range is unknown ! This is my code to return the same column. Someone to give another solution?

Private Sub OPEN_MSG_Click()
    Dim FindString$
    Dim MyValue   
    Dim objExcel, objsheet, WB,WS As Object

    'Open excel file
    Set objExcel = CreateObject("Excel.Application")
    objExcel.Visible = False

    Set WB = objExcel.Workbooks.Open("C:\Program Files (x86)\Proficy\Proficy iFIX\ProjectBackup\Foutcode_Opgezuiverd.xlsx")
    WB.ACTIVATE

    Set WS = WB.Worksheets("Blad1")
    'Set objsheet = objExcel.ActiveWorkbook.Worksheets(1)

    FindString = InputBox("Enter a Search value")

    With WS.Range("A1:A800")
        Set MyValue = .Find("FindString", LookIn:=xlValues)
        If Not MyValue Is Nothing Then
            MsgBox MyValue.Column
        MsgBox MyValue.row
        End If
    End With

    ' Save the spreadsheet and close the workbook.
    objExcel.ActiveWorkbook.Close
    ' Quit Excel.
    objExcel.Application.Quit

End Sub
1
  • Does it work or not? Range is only a datatype in Excel. Just leave it as Variant. Commented Aug 10, 2017 at 9:09

1 Answer 1

1

In the find method you ask it to search for "FindString" as a string. Since you want to find the value within FindString you should remove the "".

    Set MyValue = .Find(FindString, LookIn:=xlValues)

You might also want to declare Findstring as a string to avoid errors with the find method.

Sign up to request clarification or add additional context in comments.

Comments

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.