+ Reply to Thread
Results 1 to 6 of 6

Insert shift down issue macro issue

Hybrid View

  1. #1
    Registered User
    Join Date
    10-11-2012
    Location
    Oz
    MS-Off Ver
    Excel 2010
    Posts
    5

    Insert shift down issue macro issue

    Hi,

    Could someone please give me some guidance with an issue I am having.

    I'm trying to copy a range of data from one sheet, paste it to another, then insert and shift down one row.

    The first example below works but if I'm working on another sheet it will always returns me to sheet two.

    The second example I think is heading in the right direction(minus .Activate and .Select) but I don't how to incorporate the insert and shift down without encountering the issues of the first example.

    Any help would be appreciated.

    Thanks,

    Simon

    Sub example1()
    Application.ScreenUpdating = False
    Sheets("one").Activate
    Sheets("one").Range("B5:Y5").Select
    Selection.Copy
    Sheets("two").Activate
    Sheets("two").Range("B5:Y5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
            Application.CutCopyMode = False
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Application.ScreenUpdating = False
        StartTimer
        
    End Sub
    
    Sub Example2()
    
                Dim srceRng As Range
                Dim destRng As Range
                Set srceRng = Workbooks("ontimemacro.xlsm").Sheets("one").Range("B5:Y5")
                Set destRng = Workbooks("ontimemacro.xlsm").Sheets("two").Range("B5:Y5")
    
    srceRng.Copy
    Workbooks("ontimemacro.xlsm").Sheets("two").Paste destRng
    
                
     StartTimer
    
    End Sub

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,086

    Re: Insert shift down issue macro issue

    Try:

    Sub example1()
    Application.ScreenUpdating = False
    Sheets("one").Range("B5:Y5").Copy
    With Sheets("two")
       .Range("B5:Y5").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
       .Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    End With
    Application.ScreenUpdating = False
    StartTimer
    End Sub

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    10-11-2012
    Location
    Oz
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Insert shift down issue macro issue

    Hi TMS,

    Thanks for your reply.

    I ran your code but received a run time 'error 438 object doesn't support property or method' on the following line.

    Thanks

    Simon

    .Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,086

    Re: Insert shift down issue macro issue

    Oops:

    Sub example1()
    Application.ScreenUpdating = False
    Sheets("one").Range("B5:Y5").Copy
    With Sheets("two")
       With .Range("B5:Y5")
          .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,  _
               SkipBlanks:=False, Transpose:=False
          .Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
       End With
    End With
    Application.ScreenUpdating = True ' <<<< also changed this from False
    StartTimer
    End Sub

    Regards, TMS

  5. #5
    Registered User
    Join Date
    10-11-2012
    Location
    Oz
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Insert shift down issue macro issue

    Thanks again for your help TMS.

    For some reason a compile error was triggered in the StartTimer macro.

    I changed the name of the procedure which seemed to fixed the problem???

    It's working so that's all that matters.

    Cheers,

    Simon

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,086

    Re: Insert shift down issue macro issue

    You're welcome.


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1