+ Reply to Thread
Results 1 to 5 of 5

VBA Function - beginner

  1. #1
    Registered User
    Join Date
    06-28-2010
    Location
    Chester, uk
    MS-Off Ver
    Excel 2003
    Posts
    2

    VBA Function - beginner

    Hi

    I just begun using VBA

    I wrote a function to extract a text item from a single row or single column of data entries. The text item chosesn is a numbered item and all non text is ignored. So if the list consisted of "AA","BB"," ","DD","EE" say then the input agruments (3,list) to the function would generate the result DD and similarly (2,list) would generate the result BB.

    I wrote the function "nonzerotext" and the test harness subroutine "showtext" to display the output in a message box. This worked.

    However, the function does not work alone in the spreadsheet. Any ideas.

    See function and test harness below.

    Please Login or Register  to view this content.
    Last edited by Leith Ross; 03-13-2011 at 10:28 PM. Reason: Added Code Tags

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: VBA Function - beginner

    Hi steve427,
    welcome to the forum

    Please Login or Register  to view this content.
    no need for private as it "Indicates that the Function procedure is accessible only to other procedures in the module where it is declared." VBA help
    and to return the value in one sting
    Please Login or Register  to view this content.
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: VBA Function - beginner

    just clicked what you are doing. the number "numdetected" needs to progress on every loop
    the
    Please Login or Register  to view this content.

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,673

    Re: VBA Function - beginner

    I don't quite see the need for the loop and counter using your example; however, the code below solves the immediate problem.
    Please Login or Register  to view this content.
    Your original code did not work with the example because you had an empty cell in the range but your counter is not adjusted to account for it so that after that cell the count is off by one...
    Ben Van Johnson

  5. #5
    Registered User
    Join Date
    06-28-2010
    Location
    Chester, uk
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: VBA Function - beginner

    Many thanks for all the replies.

    Having looked at the code you all posted it gave me an idea how to solve it.

    I changed the way I addressed the range and that seemed to do it.

    Thanks
    Steve

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1