Adding Rows to Specific Sections within a Table

emcgaffin

New Member
Joined
Sep 8, 2017
Messages
10
Hello everyone!

I am trying to record a few macros that would allow me to add rows to each stage when necessary. Ideally I would click a button (I have multiple buttons) and it would insert a row in a specific stage. For example, if I need to add a row for Stage 0 I would like the macro to add a row directly above Stage 1. I have tried multiple times and I can not get it right.

Thanks for the help!


Project Plan Sample V2 Master.xlsm
BCDE
7TaskStartProjected EndDate
9Stage 0
10Task 15/24/20215/25/20215/31/2021
11Task 26/1/20216/6/20215/31/2021
12Task 36/5/20216/10/20215/31/2021
13Task 47/1/20217/6/20215/31/2021
14Stage 1: Define/Workflow 
15Task 15/30/20216/12/20215/31/2021
16Task 26/12/20216/28/20215/31/2021
17Task 3 
18Task 4 
19Task 5 
20Task 6 
21Task 7 
22Task 8 
23Stage 2: Integration 
24Task 1 
25Task 2 
26Task 3 
27Task 4 
28Stage 3: Testing 
29Task 115-Jun28-Jun31-May
30Task 25-Jun24-Jun31-May
31Task 330-Jun15-Jul31-May
32Task 42-Jul15-Jul31-May
33Task 55-Jun20-Jun31-May
Gantt Project Revised (2)
Cell Formulas
RangeFormula
C10C10=Start_Date
D11:D13D11=C11+5
E10:E33E10=IF(D10>0,TODAY(),"")
Named Ranges
NameRefers ToCells
'Gantt Project Revised (2)'!Start_Date='Gantt Project Revised (2)'!$D$3C10
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
This is an example on how you can detect Stage 1 and insert row. This is not probably what you exactly need since you did not mention what is the condition to insert row.
VBA Code:
Sub Test()

Dim cell As Range, rngColA As Range

Set rngColA = Range("A3", Cells(Rows.Count, "A"))

For Each cell In rngColA
    Select Case cell
        Case "Stage 1: Define/Workflow"
            cell.EntireRow.Insert
        Case "Stage 2: Integration"
        
        Case "Stage 3: Testing"
        
    End Select
Next
    
End Sub
 
Upvote 0
Oppss. my bad. The code is not correct. Here is the corrected one
VBA Code:
Sub Test()

Dim cell As Range, rngColA As Range

Application.ScreenUpdating = False
Set rngColA = Range("A3", Cells(Rows.Count, "A").End(xlUp))

For Each cell In rngColA
    Select Case cell
        Case "Stage 1: Define/Workflow"
            cell.EntireRow.Insert
        Case "Stage 2: Integration"
        
        Case "Stage 3: Testing"
        
    End Select
Next
Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Sorry. It cannot work that way. I will need to rework the code :(. I did not test it before
 
Upvote 0
This is the corrected code
VBA Code:
Sub Test()

Dim n As Long, eRow As Long
Dim cell As Range

Application.ScreenUpdating = False
eRow = Cells(Rows.Count, "B").End(xlUp).Row

For n = eRow To 7 Step -1
    Select Case Range("B" & n)
        Case "Stage 1: Define/Workflow"
            Range("B" & n).EntireRow.Insert
        Case "Stage 2: Integration"
        
        Case "Stage 3: Testing"
        
    End Select
Next
Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Solution
This is an example on how you can detect Stage 1 and insert row. This is not probably what you exactly need since you did not mention what is the condition to insert row.
VBA Code:
Sub Test()

Dim cell As Range, rngColA As Range

Set rngColA = Range("A3", Cells(Rows.Count, "A"))

For Each cell In rngColA
    Select Case cell
        Case "Stage 1: Define/Workflow"
            cell.EntireRow.Insert
        Case "Stage 2: Integration"
       
        Case "Stage 3: Testing"
       
    End Select
Next
   
End Sub
Thanks Zot! I will mess with it now! Have a great day.
 
Upvote 0
This is the corrected code
VBA Code:
Sub Test()

Dim n As Long, eRow As Long
Dim cell As Range

Application.ScreenUpdating = False
eRow = Cells(Rows.Count, "B").End(xlUp).Row

For n = eRow To 7 Step -1
    Select Case Range("B" & n)
        Case "Stage 1: Define/Workflow"
            Range("B" & n).EntireRow.Insert
        Case "Stage 2: Integration"
       
        Case "Stage 3: Testing"
       
    End Select
Next
Application.ScreenUpdating = True
   
End Sub
This was exactly what I needed. Thank you for the explanation! This works perfectly.
 
Upvote 0
Thanks for updates. I 'm the one who messed up in the first place ?
 
Upvote 0

Forum statistics

Threads
1,214,805
Messages
6,121,656
Members
449,045
Latest member
Marcus05

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