Hello! I am getting an "Else without If" error message on the following code. How can I make it recognize the Else for the second If statement? Thanks!
(The purpose of the macro is to format a column or set of columns in a pivot table, beginning on row 4, based on how many data points there are in row 5. Think row 4 is Fruits, and row 5 is Apples, Oranges, Grapes. This grouping will be 3 columns wide. The next value in Row 4 is Vegetables, but there's only one value, Broccoli. This formatting will only apply to a single column.)
(The purpose of the macro is to format a column or set of columns in a pivot table, beginning on row 4, based on how many data points there are in row 5. Think row 4 is Fruits, and row 5 is Apples, Oranges, Grapes. This grouping will be 3 columns wide. The next value in Row 4 is Vegetables, but there's only one value, Broccoli. This formatting will only apply to a single column.)
Code:
If ActiveCell = "Grand Total" Then Call SOWGrandTotal ElseActiveCell.Offset(0, 1).Select
If ActiveCell <> "" _
Then ActiveCell.Offset(0, -1).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Selection.Resize(lastrow).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Else
Selection.End(xlToRight).Select
ActiveCell.Offset(0, -1).Select
Range(Selection, Selection.End(xlToLeft)).Select
'goes into formatting the "else" selection
Last edited: