If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Compile Error: End if wtihout block if

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-04-08, 12:36
lijon lijon is offline
Registered User
 
Join Date: Mar 2008
Posts: 8
Compile Error: End if wtihout block if

HI EVERYONE... I keep getting the error above and can't seem to figure out where my End If's are supposed to be. Please help. Mucho Gracias!!

sRow = 2

Range("a1").Select
If Range("a1").Offset(1, 0).Value <> "" Then
Selection.End(xlDown).Select
End If
eRow = ActiveCell.Row

For cnt = sRow To eRow

If Left(Range("a" & cnt).Value, 3) = "Buy" Or Left(Range("a" & cnt).Value, 4) = "Sell" _
Then Range("A" & cnt).Offset(0, 11).Value = (Range("A" & cnt).Offset(0, 3).Value / 1000000) * Range("A" & cnt).Offset(0, 5).Value
total = total + Range("A" & cnt).Offset(0, 11).Value
End If


If Left(Range("A" & cnt).Value, 5) = " t " Then Range("A" & cnt).Offset(0, 11).Value = total
End If

If Left(Range("A" & cnt).Value, 5) = " t " Then Range("A" & cnt).Offset(0, 12).Value = Range("A" & cnt).Offset(0, 11).Value _
/ (Range("A" & cnt).Offset(0, 3).Value / 1000000)

total = 0


If Left(Range("A" & cnt).Value, 5) = " t " Then Range("A" & cnt & ":" & "M" & cnt).Font.Bold = True
If Left(Range("A" & cnt).Value, 5) = " t " Then Range("A" & cnt & ":" & "M" & cnt).Interior.ColorIndex = 6
End If

Next cnt


End Sub
Reply With Quote
  #2 (permalink)  
Old 03-04-08, 13:11
michaeldavid michaeldavid is offline
Registered User
 
Join Date: Dec 2004
Posts: 35
If all on one line

Hi,

If you put the whole statement on a single line ie

If AVariable = 10 then DoSomething

Then there is no need for an "End if"
This also applies if you use a line continuation with a space and Underscore.


However if you place a line in it ie

If AVariable = 10 then
DoSomething
End If

Then there is a requirement for an "End If"

Hope this helps
Reply With Quote
  #3 (permalink)  
Old 03-05-08, 07:40
MarkReez MarkReez is offline
Registered User
 
Join Date: Mar 2008
Location: East Anglia
Posts: 7
Put some extras end if's in the last few lines - I highlighted them in red

If Left(Range("A" & cnt).Value, 5) = " t " Then Range("A" & cnt).Offset(0, 12).Value = Range("A" & cnt).Offset(0, 11).Value _
/ (Range("A" & cnt).Offset(0, 3).Value / 1000000)

total = 0
END IF

If Left(Range("A" & cnt).Value, 5) = " t " Then Range("A" & cnt & ":" & "M" & cnt).Font.Bold = True
END IF
If Left(Range("A" & cnt).Value, 5) = " t " Then Range("A" & cnt & ":" & "M" & cnt).Interior.ColorIndex = 6
End If
Reply With Quote
  #4 (permalink)  
Old 03-08-08, 12:24
norie norie is offline
Registered User
 
Join Date: Mar 2006
Posts: 163
Try this.
Code:
    sRow = 2
    
    Range("a1").Select
    
    If Range("a1").Offset(1, 0).Value <> "" Then
        Selection.End(xlDown).Select
    End If
    
    eRow = ActiveCell.Row
    
    For cnt = sRow To eRow
    
    If Left(Range("a" & cnt).Value, 3) = "Buy" Or Left(Range("a" & cnt).Value, 4) = "Sell" Then
        Range("A" & cnt).Offset(0, 11).Value = (Range("A" & cnt).Offset(0, 3).Value / 1000000) * Range("A" & cnt).Offset(0, 5).Value
        total = total + Range("A" & cnt).Offset(0, 11).Value
    End If
    
    
    If Left(Range("A" & cnt).Value, 5) = " t " Then
        Range("A" & cnt).Offset(0, 11).Value = total
    End If
    
    If Left(Range("A" & cnt).Value, 5) = " t " Then
        Range("A" & cnt).Offset(0, 12).Value = Range("A" & cnt).Offset(0, 11).Value / (Range("A" & cnt).Offset(0, 3).Value / 1000000)
    
        total = 0
    End If
    
    If Left(Range("A" & cnt).Value, 5) = " t " Then
        Range("A" & cnt & ":" & "M" & cnt).Font.Bold = True
        Range("A" & cnt & ":" & "M" & cnt).Interior.ColorIndex = 6
    End If
    
    Next cnt
Note as well as sorting the If/End Ifs I've indented the code.

Doing that makes it far easier to read and far easier to debug.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On