Consulting

Results 1 to 7 of 7

Thread: Solved: Help with value testing

  1. #1

    Solved: Help with value testing

    Hi,
    Struggling a bit with the logic (and code) for the following

    I need to rest the contents of a cell e.g. A1 and run some code depending on its value - I have 3 different situations

    1

  2. #2
    whoops

    is the cell zero or above

    is the cell below zero but not greater than -1

    is the cell less than -1

    thanks

    Jon

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    With Range("A1")

    If .Value2 < -1 Then

    'do something
    ElseIf .Value2 < 0 Then

    'do something else
    Else

    'final do something else
    End If
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Thanks XLD - might have confused things - I will explain more

    If cell value is 0(zero) or above the do nothing

    If cell value is below zero but not greater than -1 then do something

    If cell value is less than -1 (e.g. -1.2) then do something else

    Does your logic still apply?

    thanks again

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Yeah, the final do something else is just do nothing.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Whilst not needed here, check out Select Case in VBA Help if you have multiple options.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by mdmackillop
    Whilst not needed here, check out Select Case in VBA Help if you have multiple options.
    As you say. may not be needed here, but it is always more readable (IMO).
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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