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!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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".
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,113,998
Members
448,541
Latest member
iparraguirre89

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top