+ Reply to Thread
Results 1 to 13 of 13

Automatically shifting cells

Hybrid View

  1. #1
    Registered User
    Join Date
    10-23-2008
    Location
    toronto
    Posts
    19

    Automatically shifting cells

    Hello. first time posting on the forum. Seems to be great help over here so I decided to give it a shot.


    I'm looking to create a program that enables the macro to run with placing the desired cell blocks (A3:F12) from Sheet1 into Sheet2, and when i press the shortcut key again, it automatically places the cell blocks underneath the previous data that was pasted in the Sheet2. The goal of this is to keep a history of the data into the Sheet2.

    I'm new to this, especially with VBA but is there any possible way to create this type of macro program? Thank you in advance.
    Last edited by VBA Noob; 10-23-2008 at 05:21 PM.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    see if this gets you started

    Sub MoveData()
    Dim SrcRng As Range
    Dim LastC As Range
    
    Set LastC = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1)
    Set SrcRng = Sheets("Sheet1").Range("A3:F12")
    
        SrcRng.Copy LastC
        Application.CutCopyMode = False
    
    End Sub
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    10-23-2008
    Location
    toronto
    Posts
    19
    Thanks for the help.


    I plugged in the code and what it does is after pasting the first set of data, the cells don't shift down, but rather erases the first row from the very top and continues to do so everytime i press the shortcut key until the all rows of the data are disappeared. I think you could be onto something though.

    Would you know what can be solved in this case?


    Edit: I just realized, it only deletes the rows when i stay in the Sheet2 window. If im in the Sheet1 window and press the shortcut key, data is only replaced in Sheet2, not added below.
    Last edited by w_lred; 10-23-2008 at 03:43 PM.

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    The code posts range A3:F12 in sheet 1 to the either the last cell in Col A in Sheet 2 or if it's blank then A2

    can you post a sample of what you're after if the above is wrong

    VBA Noob

  5. #5
    Registered User
    Join Date
    10-23-2008
    Location
    toronto
    Posts
    19
    Ok. I hope i can explain this clearly.

    I would like to move cells A3:F12 from Sheet1 to cell blocks A1:F10 in Sheet2.

    Now, when i want to change the data (from Sheet1) and press the shortcut key, it will transfer the new data below the first set of data (in Sheet2) to cells A13:F21 (since I would like to keep 2 rows of space).

    I would like to have it continue to place sets of datas below eachother infinitely (keeping 2 row spaces free between each set).

    Does this help a little?

    * I attached the file, the one i'm working on.
    Attached Files Attached Files
    Last edited by w_lred; 10-23-2008 at 04:03 PM.

  6. #6
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Is this any better

    Sub MoveData()
    Dim SrcRng As Range
    Dim LastC As Range
    
    
    Set SrcRng = Sheets("Sheet1").Range("A3:F12")
    
    If WorksheetFunction.CountA(Sheets("Sheet2").Columns(1)) > 1 Then
        Set LastC = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(3)
    Else
        Set LastC = Sheets("Sheet2").Range("A1")
    End If
    
        SrcRng.Copy LastC
        Application.CutCopyMode = False
    
    Set LastC = Nothing
    Set SrcRng = Nothing
    End Sub
    VBA Noob

+ 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