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