+ Reply to Thread
Results 1 to 2 of 2

Insert rows in sheet with specific format and data

Hybrid View

ninikaki Insert rows in sheet with... 10-19-2015, 09:46 AM
vichopalacios Re: Insert rows in sheet with... 10-20-2015, 02:21 PM
  1. #1
    Registered User
    Join Date
    04-30-2012
    Location
    athens
    MS-Off Ver
    Excel 2010
    Posts
    1

    Insert rows in sheet with specific format and data

    Good Afternoon,

    First of all I want to clarify that these days I make my first steps in VBA...

    I have an excel file with ~2500 rows.
    Some times in the month, I have to input data in this sheet, after certain headers.
    Also, I have to put blank lines for the headers that I do not have data.

    For example, in the picture below, you can see the entries of OCT 19

    sample.png

    What I want to do, is create a macro which will insert every time a new line

    sample2.png

    before line with headers (header 2a, header 2b etc)

    I tried to create a macro, but with no success....


    Sub INSERT_ROWS()
    Dim i As Long, y As Long
    For i = Range("c" & Rows.Count).End(3).Row To 2 Step -1
    If Cells(i, "c").Offset(y) = "HEADER 1" Then
    Rows(i).Insert
    End If
    Next i
    End Sub


    Could, someone help me pls?..

  2. #2
    Valued Forum Contributor
    Join Date
    08-07-2014
    Location
    Quito, Ecuador
    MS-Off Ver
    Excel 2016 & 365, Windows 10
    Posts
    511

    Re: Insert rows in sheet with specific format and data

    Please check the notes in the code

    Sub INSERT_ROWS()
    
    Dim i As Long, y As Long
    'you need to asign a value to the variable "y"
    'If you put y = 0, the new row is inserted just over the "HEADER 1"
    'If you put y = -1, the new row is inserted just under the "HEADER 1"
    'If you put y = -2 the new row is inserted just under the "HEADER 2b"
    
    y = 1
    For i = Range("c" & Rows.Count).End(3).Row To 2 Step -1
            Cells(i, "c").Offset(y).Select
    'this need to assure that "HEADER 1" is in column "C"
        If Cells(i, "c").Offset(y) = "HEADER 1" Then
            Rows(i).Insert
        End If
    Next i
    
    End Sub
    Barriers are there for those who don't want to dream

+ 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. [SOLVED] Macro to insert specific number of rows, populate rows with data above except date
    By Melissa Camp in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-08-2015, 03:59 PM
  2. [SOLVED] Searching Values that Follow a Specific Format and Copy Rows to a New Sheet
    By aviatecar in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-18-2014, 07:11 AM
  3. Replies: 1
    Last Post: 11-20-2012, 10:01 PM
  4. HALP! Count and Insert Rows and Specific Data on Another Sheet.
    By goradiar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-13-2012, 08:00 AM
  5. Replies: 0
    Last Post: 09-17-2012, 11:10 AM
  6. Copy and insert rows with contents and format based on specific number
    By fatalcore in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-13-2012, 03:38 AM
  7. Insert multiple rows in specific sections of sheet?
    By Marylander in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-30-2007, 01:12 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