+ Reply to Thread
Results 1 to 4 of 4

Macro code to insert 3 rows on spreadsheet with variable number of rows

Hybrid View

D18GE Macro code to insert 3 rows... 06-14-2013, 02:46 PM
JOHN H. DAVIS Re: Macro code to insert 3... 06-14-2013, 03:51 PM
D18GE Re: Macro code to insert 3... 06-14-2013, 04:48 PM
JOHN H. DAVIS Re: Macro code to insert 3... 06-17-2013, 07:33 AM
  1. #1
    Registered User
    Join Date
    06-09-2013
    Location
    Oklahoma
    MS-Off Ver
    Excel 2010
    Posts
    24

    Macro code to insert 3 rows on spreadsheet with variable number of rows

    I have a need to include the macro code to insert three blank rows on the 2nd to last row
    "and" add text in cell columns C & D associated with the added rows. If the existing file
    has 13 columns, the new file would have 13 rows. I can't overwrite the last row information
    as I am trying to just push it down 3 rows.

    The spreadsheet the macro calls up is an existing spreadsheet data base file and the existing number of rows will have to be determined.
    All the columns have the same number of rows and the last row is sum of the columns. I'm trying to insert 3 new rows above the
    above the last row and also "hard code" text in the Columns C and D associated with the new rows.

    For help purposes the sample text could be
    "text C1" .. located on the 1st new inserted row & 2th Column (Col C) "text D1" .. located 1st new row column D
    "text C2" .. located on the 2nd new inserted row and 4th Column (Col D) "text D2" .. located 2nd new row column D
    "text C3" .. located at the 3rd new inserted row and 4th Column (Col D) "text D3" .. located 3rd new row column D

    Thanks in advance for any suggestions or help.
    Last edited by D18GE; 06-14-2013 at 02:56 PM.

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro code to insert 3 rows on spreadsheet with variable number of rows

    If I understand correctly maybe:

    Sub D18GEa()
    Range("A" & Rows.Count).End(3)(0).EntireRow.Resize(3).Insert xlDown
    Range("C" & Rows.Count).End(3)(-3).Select
    ActiveCell.Value = "text C1"
    ActiveCell.Offset(, 1).Value = "text D1"
    ActiveCell.Offset(1).Value = "text C2"
    ActiveCell.Offset(1, 1).Value = "text D2"
    ActiveCell.Offset(2).Value = "text C3"
    ActiveCell.Offset(2, 1).Value = "text D3"
    End Sub

  3. #3
    Registered User
    Join Date
    06-09-2013
    Location
    Oklahoma
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Macro code to insert 3 rows on spreadsheet with variable number of rows

    John, You understood my narrative perfectly. The code works great.
    Thank you for your quick reply and assistance. This gets my project
    wrapped up.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro code to insert 3 rows on spreadsheet with variable number of rows

    You're welcome. Glad to help out and thanks for the feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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