vba比较日期大小,定义日期;vba让excel保存

Private Sub CommandButton1_Click()
Dim i, j As Integer
Dim a As Date
a = #10/1/2013#
j = 2
i = 2
' If  Worksheets("改后B").Range("a" & CStr(i)) = Worksheets("改后A").Range("a" & CStr(j)) And Worksheets("改后B").Range("b" & CStr(i)) = Worksheets("改后A").Range("b" & CStr(j)) And Trim(Worksheets("改后B").Range("c" & CStr(i))) = Trim(Worksheets("改后A").Range("c" & CStr(j))) And Trim(Worksheets("改后B").Range("d" & CStr(i))) = Trim(Worksheets("改后A").Range("d" & CStr(j))) Then
'  MsgBox DateDiff("d", Worksheets("改后B").Range("a" & CStr(560)), 2013 - 10 - 1)
  'End If

For i = 2801 To 3500
  j = 2
   While Worksheets("改后A").Range("a" & CStr(j)) <> ""
   
     If Worksheets("改后B").Range("a" & CStr(i)) < a Then
      If Worksheets("改后B").Range("a" & CStr(i)) = Worksheets("改后A").Range("a" & CStr(j)) And Worksheets("改后B").Range("b" & CStr(i)) = Worksheets("改后A").Range("b" & CStr(j)) And Trim(Worksheets("改后B").Range("c" & CStr(i))) = Trim(Worksheets("改后A").Range("c" & CStr(j))) And Trim(Worksheets("改后B").Range("d" & CStr(i))) = Trim(Worksheets("改后A").Range("d" & CStr(j))) Then
        Worksheets("改后B").Range("p" & i) = Worksheets("改后A").Range("e" & j)
        Worksheets("改后B").Range("q" & i) = Worksheets("改后A").Range("f" & j)
        Worksheets("改后B").Range("r" & i) = Worksheets("改后A").Range("g" & j)
        Worksheets("改后B").Range("s" & i) = Worksheets("改后A").Range("h" & j)
        Worksheets("改后B").Range("t" & 2) = i
        If i Mod 100 = 0 Then
           ThisWorkbook.Save
        End If
GoTo ee
      End If
    End If
     If Worksheets("改后B").Range("a" & CStr(i)) > a Then                             比较日期
         Worksheets("改后B").Range("t" & i) = "日期大于表A最大日期"
         Worksheets("改后B").Range("t" & 2) = i
         If i Mod 100 = 0 Then
   保存        ThisWorkbook.Save    
        End If
GoTo ee
     End If
    j = j + 1
   Wend
ee:
Next
End Sub

你可能感兴趣的:(Excel)