+ Reply to Thread
Results 1 to 6 of 6

cut then move (insert or paste) range

Hybrid View

  1. #1
    Registered User
    Join Date
    02-03-2010
    Location
    earth
    MS-Off Ver
    Excel 2007
    Posts
    3

    cut then move (insert or paste) range

    Hi. I'm having a toughs time with what I thought was a simple task. I need to cut and insert/paste a range of cells and then repeat in a loop.

    Explicitly, I have 3 columns with 2990 rows. Every 46 rows is a 'group' and I want to cut each group and paste at the top of the sheet so I have only 46 rows and (2990/46*3) 195 columns. I need to preserve the order so that the group at the bottom becomes the rightmost group.

    More simply, I have

    xxx
    xxx
    xxx
    yyy
    yyy
    yyy
    zzz
    zzz
    zzz

    and I want
    xxx yyy zzz
    xxx yyy zzz
    xxx yyy zzz

    From searching around, I tried to write a simple code but obviously I'm not handling the variables right, but you get the idea.

    Sub ci()
    
    For j = 2945 To 47 Step -46
    
        Range(Cells(1, j), Cells(3, j + 45)).Select
        Selection.Cut
        Range("A4").Select
        Selection.insert Shift:=xlRight
        Next j
        
        
    End Sub
    Thanks for any help.
    Last edited by coregis; 02-03-2010 at 04:32 AM.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: cut then move (insert or paste) range

    earthing
    try
    Sub ci()
    For j = Cells(Rows.Count, 1).End(xlUp).Row To 3 Step -3
     v = v + 1
        Range(Cells(j, 1), Cells(3 + j, 1)).Cut Destination:=Cells(1, 3 + v)
         Next j
    End Sub
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Registered User
    Join Date
    02-03-2010
    Location
    earth
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: cut then move (insert or paste) range

    Thanks for the effort, but it didn't work... it's grabbing 3 rows from one column (the first one) instead of 3 columns from 46 rows and it fails before the end. I don't understand what is going on and playing with it is not going to well... I appreciate it though.

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: cut then move (insert or paste) range

    assumed that you just needed the structure

    looks better.. try

    Sub ci()
    For j = 47 To Cells(Rows.Count, 1).End(xlUp).Row Step 46
     v = v + 3
        Range(Cells(j, 1), Cells(46 + j, 3)).Cut Destination:=Cells(1, 3 + v)
         Next j
    End Sub

  5. #5
    Registered User
    Join Date
    02-03-2010
    Location
    earth
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: cut then move (insert or paste) range

    Quote Originally Posted by pike View Post
    assumed that you just needed the structure

    looks better.. try
    Thanks, I get it now.

  6. #6
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: cut then move (insert or paste) range

    earthling
    your first code was very close, and its good to see someone having a go, it just need a tune up
    well done!
    thanks for marking the post [SOLVED]

+ 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