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

核能气质少年 提交于 2020-01-16 01:55:11

问题


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

来源:https://stackoverflow.com/questions/21392069/why-error1004-unable-to-set-the-numberformat-property-of-the-range-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!