Kamis, 02 April 2015

Re: [ExcelVBA] Simple loop help

 



What exactly are the errors?  If you don't tell us, how can we help you?
 
FWIW I copied your code into a sheet module and called it from a button event and it ran without trouble and did what it looks like it's supposed to.
 
A couple of points ...
 
1)  Else should not be followed by a colon.  The statement to follow the Else should be on the next line, in the same way that the statements following the If and ElseIf lines are on following lines.  Doesn't stop it working - it's just bad coding style.
 
2)  Ace should not be triggered by a value of 14.  Ace is 1, there is no "1" card.

Regards, Dave S
 
----- Original Message -----
Sent: Friday, April 03, 2015 1:10 PM
Subject: [ExcelVBA] Simple loop help

Hi All,

Having difficulty running this loop. I am try to determine the integer value of a cell to return its card rank. i.e. 2=2

9=9

11=Jack

12=Queen

etc...

Here is the code, but I get multiple errors.


Private Sub RankCheck()

Dim i As Integer, CurrentCell As Long


For i = 1 To 52
    CurrentCell = Cells(i, 1)
        If Int(CurrentCell) = 11 Then
            Cells(i, 2).Value = "Jack"
        ElseIf Int(CurrentCell) = 12 Then
            Cells(i, 2).Value = "Queen"
        ElseIf Int(CurrentCell) = 13 Then
            Cells(i, 2).Value = "King"
        ElseIf Int(CurrentCell) = 14 Then
            Cells(i, 2).Value = "Ace"
        Else: Cells(i, 2).Value = Int(CurrentCell)
        End If
Next i

End Sub



Any help is appreciated. 

No virus found in this message.
Checked by AVG - www.avg.com
Version: 2015.0.5863 / Virus Database: 4321/9441 - Release Date: 04/02/15

__._,_.___

Posted by: "David Smart" <smartware.consulting@gmail.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)
----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------

.

__,_._,___

Tidak ada komentar:

Poskan Komentar