Insert row & format on specific value, then repeat w/ new value

Lovatoj44

New Member
Joined
Feb 26, 2018
Messages
1
Hello
I am trying to add an entire row to a worksheet based upon a specific cell value = "knowledge Base", then format the inserted row. The worksheet has multiple cells with the value "Knowledge Base", but I wish to insert to new row above. I would then like to add a separate row based upon a separate specific cell value = "Development". The search range is column E for both values, but the total number of rows is dynamic.

I have successfully been able to add the first row and have been able to format the first inserted row, but I cannot seem to get a the code to work when trying to add a separate second row. I have very limited experience working with for each statements and I am not sure where I am messing up at any help would be greatly appreciated.

Regards,
Josh


Code:
Dim ComboLastRow As Range
Set ComboLastRow = Combo.Range("A1").End(xlUp).Offset(1, 0)

Dim CapSwimColumn As Range
Set CapSwimColumn = Combo.Columns("E")

Dim SwimRange As Range
Set SwimRange = Combo.Range(Cells(1, CapSwimColumn.Column), Cells(ComboLastRow.Row, CapSwimColumn.Column))

Dim kbCell As Range
For Each kbCell In SwimRange
    If kbCell.Value = "Knowledge Base" Then
    kbCell.EntireRow.Insert shift:=xlDown
    kbCell.Offset(-1, -4).Value = "=""Knowledge Base"""
    kbCell.Offset(-1, -3).Value = "=""Knowledge Base Opportunity Total: "" & COUNTIF(E:E,""Knowledge Base"")"
    kbCell.Offset(-1, -2).Value = "=""Knowledge Base Sample Total: ""& SUMIFS(M:M,E:E,""Knowledge Base"")"
    With Combo.Range(Cells(kbCell.Row, AccountColumn.Column), Cells(kbCell.Row, DollarsColumn.Column)).Offset(-1).Borders(xlEdgeBottom)
        .LineStyle = xlDouble
        .Weight = xlThick
    End With
    With Combo.Range(Cells(kbCell.Row, AccountColumn.Column), Cells(kbCell.Row, DollarsColumn.Column)).Offset(-1).Borders(xlEdgeRight)
        .LineStyle = xlDouble
        .Weight = xlThick
    End With
    With Combo.Range(Cells(kbCell.Row, AccountColumn.Column), Cells(kbCell.Row, DollarsColumn.Column)).Offset(-1).Borders(xlEdgeTop)
        .LineStyle = xlDouble
        .Weight = xlThick
    End With
    With Combo.Range(Cells(kbCell.Row, AccountColumn.Column), Cells(kbCell.Row, DollarsColumn.Column)).Offset(-1).Borders(xlEdgeLeft)
        .LineStyle = xlDouble
        .Weight = xlThick
    End With
    GoTo InsertDevelopmentSeperator
    End If
    Next kbCell

InsertDevelopmentSeperator:
    Dim devCell As Range
    For Each devCell In SwimRange
    If devCell.Value = "Development" Then
    devCell.EntireRow.Insert shift:=xlDown
    devCell.Offset(-1, -4).Value = "=""Development"""
    devCell.Offset(-1, -3).Value = "=""Development Opportunity Total: "" & COUNTIF(E:E,""Development"")"
    devCell.Offset(-1, -2).Value = "=""Development Sample Total: ""& SUMIFS(M:M,E:E,""Development"")"
    With Combo.Range(Cells(devCell.Row, AccountColumn.Column), Cells(devCell.Row, DollarsColumn.Column)).Offset(-1).Borders(xlEdgeBottom)
        .LineStyle = xlDouble
        .Weight = xlThick
    End With
    With Combo.Range(Cells(devCell.Row, AccountColumn.Column), Cells(devCell.Row, DollarsColumn.Column)).Offset(-1).Borders(xlEdgeRight)
        .LineStyle = xlDouble
        .Weight = xlThick
    End With
    With Combo.Range(Cells(devCell.Row, AccountColumn.Column), Cells(devCell.Row, DollarsColumn.Column)).Offset(-1).Borders(xlEdgeTop)
        .LineStyle = xlDouble
        .Weight = xlThick
    End With
    With Combo.Range(Cells(xCell.Row, AccountColumn.Column), Cells(devCell.Row, DollarsColumn.Column)).Offset(-1).Borders(xlEdgeLeft)
        .LineStyle = xlDouble
        .Weight = xlThick
    End With
        
    GoTo InsertPartnersSeperator
    End If
    Next devCell






 

Excel Facts

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

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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