Hi All

I'm trying to write an excel vba code that return a number with respct to 
the value of the 2nd number.
There are 5 number copied into one column(it has to be one column,project 
requiremnt)
and if the value of 2nd number in cell1 is -995.25 and 2nd number in cell2 
is > 1
it returns the value of 1st number in cell2

So The code here is

Dim logstart as Range
Set log = oSht.Range("E110:E" & lastRow)

For Each logstart In log
        If CDec(Trim(Mid(Trim(logstart.Value), 9, 7))) = -990.25 And_
  CDec(Trim(Mid(Trim(logstart.Offset(-1, 0).Value), 9, 7))) >= 1 Then
            Range("D16")= LEFT(TRIM(logstart.Offset(-1, 0).Value)),8)
        Else
           'Range("D16").Value = "Failed to Load Number"
        Exit For
        End If
    Next

Here are the data(one column E)
  #-------------------------------------------------------------
             TVD         TTEM         ROP5           GR          
TVD         VSEC 
          8340.00      -999.25        33.00        30.62      
8339.62        -7.45
          8340.50      -999.25        32.77        30.39      
8340.11        -7.46
          8341.00       183.20        32.49        22.97      
8340.63        -7.46
          8341.50       183.26        32.12        20.30      
8341.11        -7.46
          8342.00       183.71        31.07        21.75      
8341.61        -7.46
          8342.50       184.16        30.07        37.26      
8342.12        -7.47
          8343.00       184.61        30.22        58.81      
8342.62        -7.47
          8343.50       185.00        31.25        73.89      
8343.12        -7.47
          8344.00       184.87        33.16        62.18      
8343.65        -7.48
          8344.50       183.79        35.77        45.28      
8344.11        -7.48

So it should return 8341.0 because 183.20 >1 and -999.25 = -999.25
But it doesn't, it returns the first cell it in the range (which doesn't 
meet the criteria)

What is wrong with the code? Please help me, i'm stuck

 

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to