Problem searching multiple sheets in excel

Reply

Join Date: Oct 2006
Posts: 1
Reputation: jholokai02 is an unknown quantity at this point 
Solved Threads: 0
jholokai02's Avatar
jholokai02 jholokai02 is offline Offline
Newbie Poster

Problem searching multiple sheets in excel

 
0
  #1
Oct 4th, 2006
Below I have listed my code. I am having a problem searching through multiple sheets in an excel workbook. As of now, it will load cboPcMark with only the first page of search results. It will also duplicate a couple of them. Can someone please take a look. Thanks in advance.:eek:


Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. cboPcMark.Clear
  3.  
  4. Dim objExcel As Object ' Excel application
  5. Dim objBook As Object ' Excel workbook
  6. Dim objSheet As Object ' Excel Worksheet
  7.  
  8. Dim ExcelCutlist As String
  9. Dim rng As Range
  10. Dim firstAddress As String
  11. Dim PcMark As String
  12. 'Dim objSheet As Excel.Sheets
  13.  
  14.  
  15. ExcelCutlist = App.Path & "\" & "TANA EC 271 I.xls"
  16.  
  17. Set objExcel = CreateObject("excel.application")
  18. Set objBook = objExcel.Workbooks.Open(ExcelCutlist)
  19. 'Set objSheet = objBook.Worksheets.Item(1)
  20.  
  21. objExcel.Application.Visible = True
  22.  
  23. For Each objSheet In objBook.Worksheets
  24.  
  25. Set rng = Nothing
  26. With objSheet.Cells
  27. Set rng = objSheet.Range("D:E").Find(What:=txtHeat.Text, lookin:=xlValues, LookAt _
  28. :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
  29. False)
  30.  
  31. If Not rng Is Nothing Then
  32. firstAddress = rng.Address
  33. Do
  34. cboPcMark.AddItem Range(rng.Address).Offset(0, -4)
  35. Set rng = objSheet.FindNext(rng)
  36. Loop While Not rng Is Nothing And rng.Address <> firstAddress
  37. End If
  38. End With
  39.  
  40. Next objSheet
  41.  
  42. Set objSheet = Nothing
  43. If Not objBook Is Nothing Then objBook.Close
  44. Set objBook = Nothing
  45. objExcel.Quit
  46. Set objExcel = Nothing
James Davis
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC