简体   繁体   中英

VBA error 1004 on range.value when copying the worksheet

Below is the code I am using, but it throws a 1004 error on the range.value line. However it copies successfully the worksheet without formulas (just values). It's just that running this keeps throwing the error 1004.

Sub test1()     
    Dim wbNew As Workbook
    Dim wks As Worksheet
    Set wbNew = Workbooks.Add(xlWBATWorksheet)
    ThisWorkbook.Worksheets.Copy After:=wbNew.Worksheets(1)
    Application.DisplayAlerts = False
    wbNew.Worksheets(1).Delete
    Application.DisplayAlerts = True
    Application.Calculation = xlCalculationManual

    For Each wks In wbNew.Worksheets
        wks.UsedRange.Value = wks.UsedRange.Value
    Next wks
    Application.Dialogs(xlDialogSaveAs).Show
End Sub

What's the purpose of wks.usedrange.value = wks.usedrange.value? This question is independent of whether the command is permitted by VBA.

Can't understand why you trying to do this :

For Each wks In wbNew.Worksheets
    wks.UsedRange.Value = wks.UsedRange.Value
Next wks

It's like saying that x = x

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM