If Else

30percent

Board Regular
Joined
May 5, 2011
Messages
123
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have the following code. I think I have the syntax correct but somehow I got error message: Compile error: Else without If. Not sure why. Wonder if someone could help point out the problem?

Code:
finalRow = sht.Cells(sht.Rows.Count, "a").End(xlUp).Row
finalRow_minMax = sht_minMax.Cells(sht.Rows.Count, "a").End(xlUp).Row


For i = 2 To finalRow
    
    If Cells(i, 14).Value >= 0 Then
        Bucket = Cells(i, 14).Value
        Select Case Bucket
        Case 50
            Cells(i, 15).Value = Cells(i, 5).Value + 0.001
        Case 40
            Cells(i, 15).Value = Cells(i, 5).Value + 0.002
        Case 30
            Cells(i, 15).Value = Cells(i, 5).Value + 0.003
        Case 20
            Cells(i, 15).Value = Cells(i, 5).Value + 0.004
        Case 10
            Cells(i, 15).Value = Cells(i, 5).Value + 0.005
        Case 0
            Cells(i, 15).Value = Cells(i, 5).Value + 0.006
    Else
        Select Case Bucket
        Case -10
            Cells(i, 15).Value = Cells(i, 5).Value - 0.001
        Case -20
            Cells(i, 15).Value = Cells(i, 5).Value - 0.002
        Case -30
            Cells(i, 15).Value = Cells(i, 5).Value - 0.003
        Case -500
            Cells(i, 15).Value = Cells(i, 5).Value - 0.004
       End Select
    End If
    
Next
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try
Code:
finalRow = sht.Cells(sht.Rows.Count, "a").End(xlUp).Row
finalRow_minMax = sht_minMax.Cells(sht.Rows.Count, "a").End(xlUp).Row


For i = 2 To finalRow
    
    If Cells(i, 14).Value >= 0 Then
        Bucket = Cells(i, 14).Value
        Select Case Bucket
        Case 50
            Cells(i, 15).Value = Cells(i, 5).Value + 0.001
        Case 40
            Cells(i, 15).Value = Cells(i, 5).Value + 0.002
        Case 30
            Cells(i, 15).Value = Cells(i, 5).Value + 0.003
        Case 20
            Cells(i, 15).Value = Cells(i, 5).Value + 0.004
        Case 10
            Cells(i, 15).Value = Cells(i, 5).Value + 0.005
        Case 0
            Cells(i, 15).Value = Cells(i, 5).Value + 0.006
       [COLOR=#ff0000]End Select[/COLOR]
    Else
        Select Case Bucket
        Case -10
            Cells(i, 15).Value = Cells(i, 5).Value - 0.001
        Case -20
            Cells(i, 15).Value = Cells(i, 5).Value - 0.002
        Case -30
            Cells(i, 15).Value = Cells(i, 5).Value - 0.003
        Case -500
            Cells(i, 15).Value = Cells(i, 5).Value - 0.004
       End Select
    End If
    
Next
 
Upvote 0
Do you need the If?
Code:
        Select Case Bucket
            Case 50
                Cells(i, 15).Value = Cells(i, 5).Value + 0.001
            Case 40
                Cells(i, 15).Value = Cells(i, 5).Value + 0.002
            Case 30
                Cells(i, 15).Value = Cells(i, 5).Value + 0.003
            Case 20
                Cells(i, 15).Value = Cells(i, 5).Value + 0.004
            Case 10
                Cells(i, 15).Value = Cells(i, 5).Value + 0.005
            Case 0
                Cells(i, 15).Value = Cells(i, 5).Value + 0.006
            Case -10
                Cells(i, 15).Value = Cells(i, 5).Value - 0.001
            Case -20
                Cells(i, 15).Value = Cells(i, 5).Value - 0.002
            Case -30
                Cells(i, 15).Value = Cells(i, 5).Value - 0.003
            Case -500
                Cells(i, 15).Value = Cells(i, 5).Value - 0.004
        End Select
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,103
Members
452,379
Latest member
IainTru

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