borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (command button to find text on another sheet)Next Topic (Insert rows based on a value in column) New Topic New Poll Post Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : just so simple but can't figure out Solved Topic
Poster Message
justarrive
Level: Protégé

Registered: 18-10-2005
Posts: 6

icon just so simple but can't figure out

folks,
     I have a very simple problem but can't figure out the root of the problem. The code is below. Hope I could recieve your hand soon.

     Function tt(test As Range)
         If (test.Rows.Value) = 0 Then
            tt = 0
         Else
            tt = 1
          End If
       End Function

I just want to test if there is a value zero in the range (column), but it does not work.
      Thanks in advance.

18-10-2005 at 10:33 PM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: just so simple but can't figure out

Hi,

     Function tt(test As Range)
         dim r as Range
         tt = 1
         for each r in ttest.rows

             if t.cells(1,1)= 0 then
                tt = 0
                exit for
             Else
                tt = 1
              End If
          next r
       End Function


This checks the first column in all rows in the given range and returns 0 if one is found
Hope this helps,
Kieron


[Edited by stickleprojects on 19-10-2005 at 02:33 PM GMT]

____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

19-10-2005 at 02:33 PM
View Profile Send Email to User Show All Posts | Quote Reply
justarrive
Level: Protégé

Registered: 18-10-2005
Posts: 6
icon Re: just so simple but can't figure out

Thank you very much stickleprojects. However, I can't make it work. Probably, the problem is in my Excel. The if .. then .. else statement does not work properly. You have any recommendation?

19-10-2005 at 02:52 PM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: just so simple but can't figure out

Hi,
Can you bit more specific about not working properly please?
Kieron


____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

19-10-2005 at 04:38 PM
View Profile Send Email to User Show All Posts | Quote Reply
justarrive
Level: Protégé

Registered: 18-10-2005
Posts: 6
icon Re: just so simple but can't figure out

hello stickleprojects,
      even from your code (delete one t from ttest --> test.rows), I get the result as #VALUE. I assume it is a problem of MS Excel in my computer. Other than that, I don't find any reasons because it is a very simple function. All other functions that I use with if...then ...else do not work properly. You have any other suggestion?

19-10-2005 at 06:07 PM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: just so simple but can't figure out

HI,
#value means that excel doesn't understand the return value.
Are all values in your range numbers?
Apologies.. typo-s all-over the place.
Corrected Code:

     Function tt(test As Range) As Integer
         Dim r As Range
         tt = 1
         For Each r In test.Rows

             If r.Cells(1, 1).Value = 0 Then
                tt = 0
                Exit For
             Else
                tt = 1
              End If
          Next r
       End Function





____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

19-10-2005 at 11:32 PM
View Profile Send Email to User Show All Posts | Quote Reply
justarrive
Level: Protégé

Registered: 18-10-2005
Posts: 6
icon Re: just so simple but can't figure out

works perfectly. thanks.

20-10-2005 at 02:49 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : just so simple but can't figure out Solved Topic
Previous Topic (command button to find text on another sheet)Next Topic (Insert rows based on a value in column) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder