I have a program below which nearly works. One small problem. The program is designed to read through an excel spreadsheet and extract ONLY the sections where delivery date = "00/00/0000".

PROBLEM:- The program currently extracts the first record and the last record, it misses out the records in the middle.

eg. my excel spreadsheet has 4 records with a delivery date = 00/00/0000. The program extracts the first and last records where delivery date = 00/00/0000. Why does it miss the ones in the middle?

Any ideas?

VB Code:
  1. Option Explicit
  2. Dim objExcel As Object 'instead of Excel.Application
  3. Dim oXLApp As Object  'instead of Excel.Spreadsheet
  4. Dim NotShippedRow As Integer
  5. Dim CurrentCell As Range
  6.  
  7. Private Sub Command1_Click()
  8. objExcel.Worksheets("Sheet1").Select
  9. objExcel.Range("H1").Select
  10. Do Until objExcel.ActiveCell.Row = 800 'Can set this to any row number you like
  11. If objExcel.ActiveCell.Value = "00/00/0000" Then 'each time a 00/00/0000 is found copy it
  12. NotShippedRow = objExcel.ActiveCell.Row - 3
  13. Call CopyCells
  14. End If
  15.  
  16. objExcel.ActiveCell.Offset(1, 0).Select
  17. Loop
  18.  
  19.  
  20. End Sub
  21.  
  22. Sub CopyCells()
  23. Dim MyRange As Object
  24. Set MyRange = objExcel.Worksheets("Sheet1").Range(objExcel.Cells(NotShippedRow, 1), objExcel.Cells(NotShippedRow + 10, 9))
  25.  
  26. MyRange.Select
  27. Selection.Copy
  28. objExcel.Worksheets("Sheet2").Select
  29. objExcel.Range("A1").Select
  30. If objExcel.ActiveCell = "" Then
  31. objExcel.ActiveSheet.Paste
  32. objExcel.Worksheets("Sheet1").Select
  33. objExcel.Cells(NotShippedRow + 4, 8).Select
  34. Else
  35. objExcel.ActiveCell.Offset(13, 0).Select 'If one 00/00/0000 has been pasted move down 13 lines and paste the next
  36. objExcel.ActiveSheet.Paste
  37. objExcel.Worksheets("Sheet1").Select
  38. objExcel.Cells(NotShippedRow + 4, 8).Select
  39. End If
  40.  'objExcel.Quit
  41.    'Set objExcel = Nothing
  42. End Sub
  43.  
  44. Private Sub Form_Load()
  45. Set objExcel = CreateObject("Excel.Application")
  46. Set oXLApp = objExcel.Workbooks.Open(FileName:=App.Path & "\" & "New.xls")
  47. objExcel.Visible = True 'show excel or not
  48.  
  49.  
  50. End Sub
nearly