Advertisement

05.03.2005 at 12:00PM PDT, ID: 21411315
[x]
Attachment Details

type casting using VBA

Asked by andrea_macleod in Microsoft Excel Spreadsheet Software

Tags: vba, cast, string, type

Is there a way to convert a string to an integer using VBA?  I have written some nested If's inside of a loop in order to find the next available extension to use while creating a work breakdown structure.....(not important)  The code follows:

       For n = 6 To r
            If Cells(n, 4) <> "--" Then
                projectNum2 = Left(Cells(n, 4).Value, 1)
                taskExtension = Right(Cells(n, 4).Value, 1)                                
                If projectNum2 = projectNum Then                      <------------------------- comparison in question
                    If taskExtension > newTaskNum Then
                        newTaskNum = taskExtension
                        Cells(n, 11) = newTaskNum
                    End If
                End If
            End If
        Next n

       This is how I get projectNum:
           itemIndex = ChooseProject.ListIndex + 6
           projectNum = Cells(itemIndex, 2).Value


The problem is that the comparison never returns true even though I know that the two numbers are equal.  I displayed the values to be sure that they really do match.  I tried CInt(projectNum2) and it returns a "type mismatch" error.  Type casting, or otherwise, I would really appreciate any help.  Thanks.Start Free Trial
[+][-]05.03.2005 at 12:02PM PDT, ID: 13920689

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.03.2005 at 12:03PM PDT, ID: 13920704

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.03.2005 at 12:04PM PDT, ID: 13920719

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.03.2005 at 12:09PM PDT, ID: 13920764

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Excel Spreadsheet Software
Tags: vba, cast, string, type
Sign Up Now!
Solution Provided By: zorvek
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.03.2005 at 12:22PM PDT, ID: 13920863

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.04.2005 at 05:27AM PDT, ID: 13925897

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32