Pls see my coding whether any changes is required.
regards
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Sub ImportH04a(Fname)
Dim i
Dim lastrow
Dim cheqdate, cheqdate1
Dim Fname1
Fname1 = Dir(Fname)
Workbooks.OpenText FileName:=Fname, Origin:=xlWindows, StartRow _
:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 9), Array(1,
2), Array( _
11, 9), Array(12, 1), Array(41, 9), Array(51, 2), Array(61, 2),
Array(71, 1), Array(80, 1), _
Array(95, 9))
cheqdate = Cells(7, 1).Value
cheqdate1 = CDate(cheqdate)
' start testing the date
For i = 2 To 40 Step 1
If Workbooks("H04.xls").Worksheets("Check").Cells(i, 1).Value =
cheqdate1 Then
MsgBox "The H04 with this date: " & cheqdate & " already exist!"
Windows(Fname1).Close SaveChanges:=False
Exit Sub
End If
Next i
' end testing the date
lastrow = ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
For i = lastrow To 1 Step -1
If Left(Cells(i, 1), 4) <> "0000" Then
Rows(i).Delete
Else
Cells(i, 5).Value = cheqdate
End If
Next
Cells.Select
Cells.EntireColumn.AutoFit
' Application.ScreenUpdating = True
'
'Windows(Fname1).Activate
ActiveSheet.UsedRange.Select
Selection.Copy
' switch to H04 file
Windows("H04.xls").Activate
Sheets("Data").Activate
lastrow = ActiveSheet.UsedRange.Rows.Count
Cells(lastrow + 1, 1).Activate
ActiveSheet.Paste
Application.CutCopyMode = False
Sheets("Check").Activate
' put in checkdate
For i = 2 To 40 Step 1
If Cells(i, 1).Value = "" Then
Cells(i, 1).Value = cheqdate
GoTo impcwl
End If
Next i
impcwl:
Application.ScreenUpdating = True
Windows(Fname1).Close SaveChanges:=False
End Sub