+ Reply to Thread
Results 1 to 6 of 6

help find my mistake in using .find

Hybrid View

artkingjw help find my mistake in using... 04-29-2012, 04:06 AM
Sa DQ Re: help find my mistake in... 04-29-2012, 05:27 AM
artkingjw Re: help find my mistake in... 04-29-2012, 05:55 AM
artkingjw Re: help find my mistake in... 04-29-2012, 06:01 AM
artkingjw Re: help find my mistake in... 04-29-2012, 06:22 AM
artkingjw Re: help find my mistake in... 04-29-2012, 06:31 AM
  1. #1
    Registered User
    Join Date
    04-27-2012
    Location
    Canberra
    MS-Off Ver
    Excel 2010
    Posts
    19

    help find my mistake in using .find

    Function ValueFinder(min As Double, N As Integer, colsave As Long) As Long

    Dim results As Range 'the cell where min is first found
    Dim x As Long 'the row coordinate of the cell with min

    Set results = Cells.Find(what:=min, after:=Cells(ROW_DATASTART - 1, colsave), searchorder:=xlByRows, searchdirection:=xlNext) 'find the cell with value of min

    x = results.row

    ValueFinder = x 'equates function output to row of results

    End Function


    heres my function, min, N and colsave are all from a seperate sub and they are all calculated correctly. I always get an error when it reaches the part where it says: x = results.row

    i looked back and saw that when i hover over "results" while vba is already on x = results.row, results says nothing...

    this is giving me a headache

    thanks so much for helping so far, this forum has been great!

  2. #2
    Forum Contributor
    Join Date
    03-21-2012
    Location
    Ho Chi Minh city
    MS-Off Ver
    Excel 2003
    Posts
    180

    Exclamation Re: help find my mistake in using .find

    PHP Code: 
    Function ValueFinder(Min As DoubleNn As IntegerColSave As Long) As Long

    Dim Results 
    As Range           'the cell where min is first found'
    Dim x As Long                  'the row coordinate of the cell with min'

    Set results Cells.Find(what:=minafter:=Cells(ROW_DATASTART 1colsave), searchorder:=xlByRowssearchdirection:=xlNext)
     
    'find the cell with value of min'
    If Not Results Is Nothing then 
        ValueFinder 
    Results.Row   'equates function output to row of results'
        
    Exit Function 
     Else
        
    ValueFinder=0
     Ende 
    If
    End Function 

  3. #3
    Registered User
    Join Date
    04-27-2012
    Location
    Canberra
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: help find my mistake in using .find

    i just noticed something

    it could be me but... screenshot.57.jpg

    i've enlarged the font, and i think the work Range is not in blue?? like the word long...

    does that mean something or is it natural?

    if i change the capital R into a small r and click somewhere else it does change back to the capital R tho, if VBA doesn't know what it is it would not do that...

  4. #4
    Registered User
    Join Date
    04-27-2012
    Location
    Canberra
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: help find my mistake in using .find

    ok to troubleshoot this, i copied out the 2 declarations, and i put it in a seperate module to test

    and i set results to a KNOWN CELL ie

    results = ranges("a1")

    x = results.row

    debug.print x

    and i still have the same problem, the same exact error. it is worth noting that the word ranges was not in blue after i copied it as well...

    i'm sorry if i'm being a bit of a boss here but this is kinda urgent lol. appreciate all the help i can get so much

  5. #5
    Registered User
    Join Date
    04-27-2012
    Location
    Canberra
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: help find my mistake in using .find

    Dim Results As Range 'the cell where min is first found
    Dim searchcol As Range
    Dim x As Long 'the row coordinate of the cell with min

    Set searchcol = ActiveSheet.Range(Cells(ROW_DATASTART, colsave), Cells(ROW_DATASTART + N - 1, colsave)) <----- when i hover my mouse over searchcol, it doesn't say "nothing"

    With searchcol

    Set Results = Cells.Find(what:=min, after:=Cells(ROW_DATASTART - 1, colsave), searchorder:=xlByRows, searchdirection:=xlNext) <--- BUT when i hover mouse over results, it DOES say nothing, after if have f8'd over both steps

    meaning something is wrong with my cells.find thing...

  6. #6
    Registered User
    Join Date
    04-27-2012
    Location
    Canberra
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: help find my mistake in using .find

    i GOT IT

    THE ERROR COMES FROM, MIN

    min itself is calculated in the worksheet , and is to many decimal places

    but on the worksheet itself, it is formatted to be rounded to 4 dps, hence vba cant find the exact same number...

    ok so now, HOW DO I EASILY ROUND numbers in vba without using worksheet function ...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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