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!
 
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
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
 
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

This Week's Hot Topics

  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • find many based on a certain criteria
    good evening, I hope someone can help me? I have a workbook sheet 2 contains lots of data.... I would like to be able to find anything on sheet...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
  • Text Format
    I have a sheet for user to keyin the data. The format of the data can be 451 / 1903, 0012 / 9908 or 00287 / 0099. The number after the "/" is...
  • Macro to copy values across rows and transposing them and add the user id
    [FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]Hi,[/COLOR][/SIZE][/FONT] [FONT=Times New...
Top