|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Function result differs from same code for subroutinein a filtered list... but while developing it I came across this... these two pieces of code are exactly the same, except one is in a function... the subroutine returns all my filtered cells, the function returns everything!!!! any clues whats happening??? Function fRow() As String a = 0 For Each c In Sheets(1).AutoFilter.Range.SpecialCells(xlCellTypeVisible) a = a + 1 'If a = 2 Then fRow = c.Value Debug.Print c.Value Next End Function '------------------------------------ Sub fRow2() a = 0 For Each c In Sheets(1).AutoFilter.Range.SpecialCells(xlCellTypeVisible) a = a + 1 'If a = 2 Then fRow = c.Value Debug.Print c.Value Next End Sub <dave-***@ntlworld.com> wrote in message
Show quoteHide quote news:1138876048.367459.239250@g14g2000cwa.googlegroups.com... Are you sure you don't mean "Returns Nothing"? The code above won't return > this is mad... am trying to write a function to return the first cell > in a filtered list... > but while developing it I came across this... > > these two pieces of code are exactly the same, except one is in a > function... > > the subroutine returns all my filtered cells, the function returns > everything!!!! > > any clues whats happening??? > > Function fRow() As String > a = 0 > For Each c In > Sheets(1).AutoFilter.Range.SpecialCells(xlCellTypeVisible) > a = a + 1 > 'If a = 2 Then fRow = c.Value > Debug.Print c.Value > Next > End Function > '------------------------------------ > Sub fRow2() > a = 0 > For Each c In > Sheets(1).AutoFilter.Range.SpecialCells(xlCellTypeVisible) > a = a + 1 > 'If a = 2 Then fRow = c.Value > Debug.Print c.Value > Next > End Sub anything at all because the "fRow = " line is commented out. If item 2 is all you're concerned with, use something like.... > Sheets(1).AutoFilter.Range.SpecialCells(xlCellTypeVisible) fRow = c.Value 'set the function return> a = a + 1 > If a = 2 Then Exit For 'bail out of the loop and return to the caller End If -- Ken Halter - MS-MVP-VB - Please keep all discussions in the groups.. DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm Freeware 4 color Gradient Frame? http://www.vbsight.com/GradFrameCTL.htm Ken,
Thanks for your input, I dont think I was clear enough... Am in the middle of developing this but I happend on this problem as I was testing what c.value would return. the debug.print statement returns completly different results. While in the subroutine it does indeed debug.print the values of my filtered cells, with the function it debug.prints everything!! Am just lost as to why it would return different results. at the end of the day i need the function will return the second SpecialCells(xlCellTypeVisible) like the subroutine does, but rignt now the 'function' isnt behaving! hope i made this clearer, its doing my head in. :\
USB-Memorystick - serial number
Hpw to make a VB6 form appears and gets focus every 15 seconds Writing to .TXT file question Best way to extract a word from a sentence Do we have such a container control? Book for web dev with VS2005? Need help regarding the program... Please help me.. It's very Urgent color format MSComm application hangs - comEventRxOver Monthview control - run time 380 invalid property value |
|||||||||||||||||||||||