VBA Code for Inserting Rows Based on Cell Value

VeryBasicAtExcel

New Member
Joined
Aug 13, 2019
Messages
3
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!
 

Some videos you may like

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

VeryBasicAtExcel

New Member
Joined
Aug 13, 2019
Messages
3
Not sure how to edit my original post.
A | B
2 |IQ1
1 |IQ2
2 |
IQ3
2 |IQ4

<colgroup><col><col></colgroup><tbody>
</tbody>


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".
 

123DavidRhodes

New Member
Joined
Aug 8, 2019
Messages
13
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
 

VeryBasicAtExcel

New Member
Joined
Aug 13, 2019
Messages
3
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,090,010
Messages
5,411,805
Members
403,400
Latest member
Mario_

This Week's Hot Topics

Top