VBA Code for Inserting Rows Based on Cell Value
Results 1 to 4 of 4

Thread: VBA Code for Inserting Rows Based on Cell Value
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Aug 2019
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation VBA Code for Inserting Rows Based on Cell Value

    Hello all,

    I am trying to create a macro that will perform some very basic formatting. Essentially, I have a dynamic list of records that I want to display under relevant headers. I'm using a counta formula to determine how many records exist under each category. I then need the macro to insert rows underneath the header, based on that counta value. If anyone can offer some assistance or get me going in the right direction, that would be most appreciated!

  2. #2
    New Member
    Join Date
    Aug 2019
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Code for Inserting Rows Based on Cell Value

    Not sure how to edit my original post.
    A | B
    2 | IQ1
    1 | IQ2
    2 | IQ3
    2 | IQ4


    That is essentially what the data looks like. I want the macro to insert 2 rows below IQ4, 2 rows below IQ3, 1 row below IQ2, and 2 rows below IQ1. It needs to be able to handle longer lists with more variation.
    The values in both columns will change, however column B data will always begin with "IQ".

  3. #3
    New Member
    Join Date
    Aug 2019
    Posts
    8
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Code for Inserting Rows Based on Cell Value

    Try working with this code and customize it to your needs. If you have questions you may reach me at (123 davidrhodes at gmail dot com)

    If ActiveCell.Value = "IQ4" Then
    ActiveCell.Offset(1, 0).Select 'Go down one row same column
    ActiveCell.EntireRow.Insert 'Insert row
    ActiveCell.EntireRow.Insert 'Insert row
    ElseIf ActiveCell.Value = "IQ3" Then
    ActiveCell.EntireRow.Insert 'Insert row
    End If

  4. #4
    New Member
    Join Date
    Aug 2019
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Code for Inserting Rows Based on Cell Value

    Quote Originally Posted by 123DavidRhodes View Post
    Try working with this code and customize it to your needs. If you have questions you may reach me at (123 davidrhodes at gmail dot com)

    If ActiveCell.Value = "IQ4" Then
    ActiveCell.Offset(1, 0).Select 'Go down one row same column
    ActiveCell.EntireRow.Insert 'Insert row
    ActiveCell.EntireRow.Insert 'Insert row
    ElseIf ActiveCell.Value = "IQ3" Then
    ActiveCell.EntireRow.Insert 'Insert row
    End If
    Thank you for your suggestion David, however the values/number of rows to insert in Column A and the identifiers in Column B will be changing, so I cannot hard code a starting cell or the number of rows to insert.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •