Else without If error

RChapman9

New Member
Joined
Apr 1, 2008
Messages
32
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.)

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:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
There are two structures to IF...THEN statements.

One is to have the THEN clause on the same line, so the whole statement is on a single line. Using this methodology, you would not use an END IF and you cannot use ELSE.
So it would look something like:
Code:
IF a THEN b

The other one you break over multiple lines. You cannot have anything after the THEN on the same line in this instance. This requires an END IF, and you can use ELSE.
So that would look something like:
Code:
IF a THEN
    b
ELSE
    c
END IF

You want this second structure, which means you have to move the part after the THEN to the next row, and you need to add an END IF line at the very end.
 
Upvote 0

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