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!
 

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

Forum statistics

Threads
1,078,552
Messages
5,341,119
Members
399,420
Latest member
Kezra

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top