else without if error

chu123456

New Member
Joined
Jan 5, 2016
Messages
2
I'm not sure why I am getting this error message. I thought I had the correct indents, and I also made sure to have a new line after "then" in the if statements. Any suggestions? Here is my code
Code:
Sub AddMilestone()


Set s1 = ThisWorkbook.Worksheets("Release Input")
Set s2 = ThisWorkbook.Worksheets("Release Calendar")
Dim rdate As Range
Dim rlast As Long
rlast = s2.Cells(Rows.Count, "A").End(xlUp).Row
Set rdate = s2.Range("e5:sz5" & rlast)
'Set rdate = s2.Range("e5:rz29")
Set mdate = s1.Range("f2:h4")
Dim rcell As Range
Dim mcell As Range


    For Each rcell In rdate.Cells
    For Each mcell In mdate.Cells


If s1.Cells(mcell.Row, 3).Value = s2.Cells(rcell.Row, 1).Value Then
    If s1.Cells(mcell.Row, mcell.Column).Value = s2.Cells(4, rcell.Column).Value And rcell.Interior.color <> vbWhite And rcell.Interior.ThemeColor <> xlThemeColorDark1 Then
        With rcell
            If s1.Cells(mcell.Row, mcell.Column).Interior.color = vbYellow Then
                Set shp = s2.Shapes.AddShape(msoShape5pointStar, .Left, .Top, .Width, .Height)
                shp.Height = 15
                shp.Width = 15
                    With shp.Fill
                        .Visible = msoTrue
                        .ForeColor.RGB = RGB(255, 255, 0)
                        .Transparency = 0
                        .Solid
        
            ElseIf s1.Cells(mcell.Row, mcell.Column).Interior.color = vbBlue Then
                Set shp = s2.Shapes.AddShape(msoShape5pointStar, .Left, .Top, .Width, .Height)
                shp.Height = 15
                shp.Width = 15
                    With shp.Fill
                        .Visible = msoTrue
                        .ForeColor.RGB = RGB(0, 0, 0)
                        .Transparency = 0
                        .Solid
        


End With
End With
    '    ElseIf s1.Cells(rcell.Row, 6) = "" Then Exit For
End If
End If


Next mcell
Next rcell
End Sub
 
Last edited by a moderator:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Untested as I do not have a workbook with the correct layout or data, but this is how I would tweak the code if it were mine. As mentioned above there are more Ifs than End Ifs, Also I think the newer layout may be easier to follow with the eye, including swapping the ElseIf for an additional If as below:

Code:
Sub AddMilestone()




Set s1 = ThisWorkbook.Worksheets("Release Input")
Set s2 = ThisWorkbook.Worksheets("Release Calendar")
Dim rdate As Range
Dim rlast As Long
rlast = s2.Cells(Rows.Count, "A").End(xlUp).Row
Set rdate = s2.Range("e5:sz5" & rlast)
'Set rdate = s2.Range("e5:rz29")
Set mdate = s1.Range("f2:h4")
Dim rcell As Range
Dim mcell As Range




For Each rcell In rdate.Cells
For Each mcell In mdate.Cells




If s1.Cells(mcell.Row, 3).Value = s2.Cells(rcell.Row, 1).Value Then
    If s1.Cells(mcell.Row, mcell.Column).Value = s2.Cells(4, rcell.Column).Value And rcell.Interior.Color <> vbWhite And rcell.Interior.ThemeColor <> xlThemeColorDark1 Then
        
        With rcell
        
            If s1.Cells(mcell.Row, mcell.Column).Interior.Color = vbYellow Then
                Set shp = s2.Shapes.AddShape(msoShape5pointStar, .Left, .Top, .Width, .Height)
                shp.Height = 15
                shp.Width = 15
                    With shp.Fill
                    .Visible = msoTrue
                    .ForeColor.RGB = RGB(255, 255, 0)
                    .Transparency = 0
                    .Solid
                    End With
            End If


            If s1.Cells(mcell.Row, mcell.Column).Interior.Color = vbBlue Then
                Set shp = s2.Shapes.AddShape(msoShape5pointStar, .Left, .Top, .Width, .Height)
                shp.Height = 15
                shp.Width = 15
                    With shp.Fill
                    .Visible = msoTrue
                    .ForeColor.RGB = RGB(0, 0, 0)
                    .Transparency = 0
                    .Solid
                    End With
            End If
            
        End With
        
' ElseIf s1.Cells(rcell.Row, 6) = "" Then Exit For
    End If
End If




Next mcell
Next rcell
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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