从日期VBA中减去时类型不匹配

时间:2015-05-12 14:32:33

标签: date types reference numbers

以下是类型不匹配:

 ws.Cells(1, 2) = ws.Cells(1, 1) - 1

然而它仍然起作用。我已经在各个地方添加了 .Value 并且它没有任何区别(正面或负面)。我一直在使用'on error resume next'但它运行得非常慢且经常崩溃(错误) excel没有足够的资源来完成这个过程)。有什么提示吗?

提前致谢!

Sub PSOPEN(wb As Workbook)
'On Error Resume Next
'Add date range to the worksheets to allow import of correct values
Dim ws As Worksheet
With wb
    For Each ws In wb.Worksheets
        ws.Cells(1, 1) = ws.Name
        ws.Cells(1, 1).NumberFormat = "m/d/yyyy"
        ws.Cells(1, 2) = ws.Cells(1, 1).Value - 1
Dim file_date
file_date = Format(ws.Cells(1, 1), "dd.mm.yy")
Dim file_date1
file_date1 = Format(ws.Cells(1, 2), "dd.mm.yy")


     If ws.Cells(1, 1) = ws1.Cells(1, 1) Then
     ws.Activate
     Cells.Select
     Selection.Copy
     Windows("Myfile " & file_date & ".xlsm").Activate
     Sheets("Sheet1").Activate
     Cells.Select
     ActiveSheet.Paste
     ws.Activate
     End If

    If ws.Cells(1, 1) = ws1.Cells(1, 1) + 1 Then
     ws.Activate
     Cells.Select
     Selection.Copy
     Windows("Myfile " & file_date1 & ".xlsm").Activate
     Sheets("Sheet2").Activate
     Cells.Select
     ActiveSheet.Paste
     ws.Activate
     End If

    Next ws
End With

End Sub

0 个答案:

没有答案