Why Error1004: unable to set the NumberFormat prop

2019-08-04 08:02发布

Why do I get Error1004: unable to set the NumberFormat property of the Range class?

Sub ReadFile(fileName As String)
    Dim projectWb As Workbook
    Dim lastRow As Long
    Dim lastRowOutput As Long
    Dim row As Long

    Application.ScreenUpdating = False

    Set projectWb = Workbooks.Open(Range("folderPath") & fileName, False)

    lastRow = projectWb.Sheets("Beställningar").Cells.Find("*", [A1], xlValues, , xlByRows, xlPrevious).row

    For row = 64 To lastRow
            lastRowOutput = ThisWorkbook.Sheets("Output").Cells.Find("*", [A1], xlValues, , xlByRows, xlPrevious).row
            'The folloing line works
            ThisWorkbook.Sheets("Output").Range("F" & lastRowOutput + 1 & ":" & "M" & lastRowOutput + 1).Value = projectWb.Sheets("Beställningar").Range("B" & row & ":" & "I" & row).Value 'Beställning
            'The following line generates Error1004: unable to set the NumberFormat property of the Range class?
            ThisWorkbook.Sheets("Output").Range("F" & lastRowOutput + 1 & ":" & "M" & lastRowOutput + 1).NumberFormat = projectWb.Sheets("Beställningar").Range("B" & row & ":" & "I" & row).NumberFormat 'Beställning
    Next row

    'close without saving
    Application.DisplayAlerts = False
    projectWb.Close (False)
    Application.DisplayAlerts = True

    Application.ScreenUpdating = True
End Sub

0条回答
登录 后发表回答