Results 1 to 2 of 2

Thread: Searching Excel sheet from VB

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Location
    UK
    Posts
    3

    Searching Excel sheet from VB

    Ive written some basic code from reading the values in certain cells in vb and putting them into a combo box. Now ive got a text box for membership numbers, (this is just an exercise im not from a company or anything ) How can i get VB to search the excel sheet for that number?
    If the number is found then open formx else "Sorry you have enter the number incorrectly"
    Cheers

    VB Code:
    1. Dim appExcel As Object
    2. Set appExcel = CreateObject("Excel.Application")
    3.  
    4. appExcel.DisplayAlerts = False
    5. appExcel.Visible = False
    6. appExcel.ScreenUpdating = True
    7. appExcel.Workbooks.Open FileName:="C:\names.xls"
    8. appExcel.Worksheets("sheet1").Select
    9.  
    10. Private Sub Command1_Click()
    11.  
    12. If Form1.NamesCombo.ListIndex < 0 Then
    13. MsgBox "You must select a student!", vbExclamation, "Error"
    14. Exit Sub
    15. End If
    16.  
    17. On Error GoTo errhandle:
    18.  
    19. Dim appExcel As Object
    20. Set appExcel = CreateObject("Excel.Application")
    21.  
    22. Private Sub Command1_Click()
    23. appExcel.DisplayAlerts = False
    24. appExcel.Visible = False
    25. appExcel.ScreenUpdating = True
    26. appExcel.Workbooks.Open FileName:="C:\names.xls"
    27. appExcel.Worksheets("sheet1").Select
    28.  
    29. appExcel.Save
    30. appExcel.Quit
    31.  
    32. MsgBox "The records have been updated"
    33.  
    34. Exit Sub
    35. errhandle:
    36. Set appExcel = Nothing
    37. MsgBox "An error has occured: " & Err.Description
    38. appExcel.Quit
    39.  
    40. End Sub


    This is the code i am using for opening and closing VB once data has been entered. Now what i want to do, once a value is typed into a text box i want to be able to search the excel sheet for that exact value, if it is not found then "error message" else load formX
    Regards
    Last edited by RobDog888; Dec 29th, 2005 at 12:47 AM.
    Imposible is a word only to be found in the dictionary of fools.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width