Forum Discussion

AHMED_KARRAM's avatar
AHMED_KARRAM
Copper Contributor
Feb 20, 2021

run-time error '1004'

any body can help

 

Sub Customer()
'
' Customer Macro
'

'
    Range("D3:D8").Select
    Selection.Copy
    ActiveWindow.ScrollWorkbookTabs Sheets:=1
    Sheet10.Select
    Range("B2:B3").Select
    Selection.End(xlDown).Select
    Range("B4").Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(1, 0).Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=True
    Range("B12").Select
    Sheet9.Select
    Application.CutCopyMode = False
    Selection.ClearContents
    Range("D3").Select
End Sub

2 Replies

  • JMB17's avatar
    JMB17
    Bronze Contributor

    AHMED_KARRAM 

     

    Is there any data below B4? When you select B4 and hit Ctrl+Down Arrow, does it take you to the last row of the spreadsheet? If you've already selected the last physical row of the worksheet, then Offset(1,0).Select will fail with a 1004 error code.

    Range("B4").Select
        Selection.End(xlDown).Select
        ActiveCell.Offset(1, 0).Range("A1").Select
  • AHMED_KARRAM 

    It isn't really necessary to select ranges in a macro.

    Sub Customer()
    '
    ' Customer Macro
    '
    
    '
        Sheet9.Range("D3:D8").Copy
        Sheet10.Range("B4").End(xlDown).Offset(1, 0).PasteSpecial _
            Paste:=xlPasteValues, SkipBlanks:=False, Transpose:=True
        Sheet9.Range("D3:D8").ClearContents
    End Sub

Resources