+ Reply to Thread
Results 1 to 6 of 6

Select cells, insert new row, move rest of table down

  1. #1
    Registered User
    Join Date
    06-03-2015
    Location
    Vandenberg Village, CA USA
    MS-Off Ver
    2013
    Posts
    3

    Question Select cells, insert new row, move rest of table down

    I have two tables side by side. Each table has four columns. One of the tables contains more data rows than the other (but the rest of its data is identical to the short one). I need to insert rows just in the short table to move data rows down so the data in the short table matches the data in the long table.

    It's easy enough to do "by hand": highlight the four cells that need to be "pushed down", press insert, and select "shift down".

    I want to do this by selecting just the first cell in the short table row and running a macro to do the rest.
    I am unable to create the correct code to make the four cell selection.

    This is the code obtained by manually creating a macro:

    'Select the Range
    Range("E187:H187").Select
    'Insert and move the rest down
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove


    What I need is the correct code to replace the selection (line 2) so that it is generic (works in any row)

    Thank you for this opportunity to obtain help

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Select cells, insert new row, move rest of table down

    Hi Bob,
    Welcome to the forum.

    You may try something like this....

    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Registered User
    Join Date
    06-03-2015
    Location
    Vandenberg Village, CA USA
    MS-Off Ver
    2013
    Posts
    3

    Re: Select cells, insert new row, move rest of table down

    Thank you for your prompt reply!!

    Your code works perfectly (of course), but what I was trying to do was eliminate the need to highlight (or in this case, enter) the additional cells. Being lazy, I just wanted to click on the first cell and use shortcut keys to finish the process of selecting the other three cells (and do the entering and moving).

    Many years ago I did a lot of programming in Basic, Fortran IV, dBase and Lotus Script and it was easy to "tell" the program to move right 5 cells and down 3, select the 3 cells to the right, etc. I was hoping there was an equally easy way to do that in VB.

    Thank you again for your reply
    Last edited by Bob_James; 06-04-2015 at 12:07 AM.

  4. #4
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Select cells, insert new row, move rest of table down

    Okay. Then try this....

    Please Login or Register  to view this content.
    Press Alt+F8 to open Macro window --> Select InsertRows from the available macros --> Options --> Set the shortcut key as per your choice --> OK

    Now after selecting a single cell and hitting the shortcut key will do the job for you.

  5. #5
    Registered User
    Join Date
    06-03-2015
    Location
    Vandenberg Village, CA USA
    MS-Off Ver
    2013
    Posts
    3

    Re: Select cells, insert new row, move rest of table down

    So
    ActiveCell.Resize(1, 4)
    is the code to increase the selection

    Super. Thank you

  6. #6
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Select cells, insert new row, move rest of table down

    You're welcome Bob!

    If that takes care of your original question, please mark your thread as Solved by selecting Thread Tools (just above your first post) --> Mark thread as solved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 12-16-2013, 12:03 PM
  2. Need hyperlink to move to another worksheet with rest of the row
    By DJ_Rutts in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-29-2011, 05:42 PM
  3. Macro : To find word and Select rest after this cell and delete rest
    By Zortabello in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-08-2010, 08:06 AM
  4. [SOLVED] Cells that move with the rest of the worksheet
    By Brandon in forum Excel General
    Replies: 5
    Last Post: 09-15-2005, 05:05 PM
  5. Select range of cells and move
    By Dan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-04-2005, 07:06 PM

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