+ Reply to Thread
Results 1 to 10 of 10

Can a Macro contain an IF statement? How?

Hybrid View

  1. #1
    MysticMarley
    Guest

    Can a Macro contain an IF statement? How?

    When my macro starts, I would like for it to reference a value from a cell
    then perform one of two actions based upon the value. Is this possible?
    Please, explain how.

  2. #2
    Norman Jones
    Guest

    Re: Can a Macro contain an IF statement? How?

    Hi MysticMarley:

    Here is a simple example:

    '===============>>
    Sub Tester()
    Dim rng As Range

    Set rng = ActiveSheet.Range("A1")

    With rng
    If .Value > 100 Then
    'Do something, e.g.:
    .Interior.ColorIndex = 3
    Else
    'Do something else, e.g.:
    .Interior.ColorIndex = 5
    End If
    End With
    End Sub

    '<<===============

    ---
    Regards,
    Norman



    "MysticMarley" <[email protected]> wrote in message
    news:[email protected]...
    > When my macro starts, I would like for it to reference a value from a cell
    > then perform one of two actions based upon the value. Is this possible?
    > Please, explain how.




  3. #3
    MysticMarley
    Guest

    Re: Can a Macro contain an IF statement? How?

    Thank you, Norman. I never would have figured that one out by myself.
    That's a huge help!

    "Norman Jones" wrote:

    > Hi MysticMarley:
    >
    > Here is a simple example:
    >
    > '===============>>
    > Sub Tester()
    > Dim rng As Range
    >
    > Set rng = ActiveSheet.Range("A1")
    >
    > With rng
    > If .Value > 100 Then
    > 'Do something, e.g.:
    > .Interior.ColorIndex = 3
    > Else
    > 'Do something else, e.g.:
    > .Interior.ColorIndex = 5
    > End If
    > End With
    > End Sub
    >
    > '<<===============
    >
    > ---
    > Regards,
    > Norman
    >
    >
    >
    > "MysticMarley" <[email protected]> wrote in message
    > news:[email protected]...
    > > When my macro starts, I would like for it to reference a value from a cell
    > > then perform one of two actions based upon the value. Is this possible?
    > > Please, explain how.

    >
    >
    >


  4. #4
    R. Choate
    Guest

    Re: Can a Macro contain an IF statement? How?

    Hi Norman,

    You know, people used to be very gracious when they got help here. Now I almost never even see anybody say thank you for the help
    they just got. Here you helped this guy hours ago and he didn't even say thank you. I chewed some other guy out who calls himself
    "Kamakshi" because he was rudely dismissing the help he got from Bob Phillips and just re-posting the problem again just an hour
    later. Such a jerk. I sent him a link to the Newsgroup netiquette site so he could do some needed reading. Since this guy wouldn't
    thank you for helping him, I will. Thank you for helping this person and anybody else you help, even when you don't get thanked or
    acknowledged in any way.

    Richard
    --
    RMC,CPA


    "Norman Jones" <[email protected]> wrote in message news:udro%[email protected]...
    Hi MysticMarley:

    Here is a simple example:

    '===============>>
    Sub Tester()
    Dim rng As Range

    Set rng = ActiveSheet.Range("A1")

    With rng
    If .Value > 100 Then
    'Do something, e.g.:
    .Interior.ColorIndex = 3
    Else
    'Do something else, e.g.:
    .Interior.ColorIndex = 5
    End If
    End With
    End Sub

    '<<===============

    ---
    Regards,
    Norman



    "MysticMarley" <[email protected]> wrote in message
    news:[email protected]...
    > When my macro starts, I would like for it to reference a value from a cell
    > then perform one of two actions based upon the value. Is this possible?
    > Please, explain how.





  5. #5
    MysticMarley
    Guest

    Re: Can a Macro contain an IF statement? How?

    Maybe you should read the replies before you spit your hatred from your rude
    pie-hole. Unfortunately, I had to get some sleep after my initial post.
    When I arose this morning I read and used Norman's very helpful solution. I
    told him so in the "thank you" reply that I posted... an hour before your
    posted sanctimonious lecture.

    Looks like you're the "jerk", Choate!

    "R. Choate" wrote:

    > Hi Norman,
    >
    > You know, people used to be very gracious when they got help here. Now I almost never even see anybody say thank you for the help
    > they just got. Here you helped this guy hours ago and he didn't even say thank you. I chewed some other guy out who calls himself
    > "Kamakshi" because he was rudely dismissing the help he got from Bob Phillips and just re-posting the problem again just an hour
    > later. Such a jerk. I sent him a link to the Newsgroup netiquette site so he could do some needed reading. Since this guy wouldn't
    > thank you for helping him, I will. Thank you for helping this person and anybody else you help, even when you don't get thanked or
    > acknowledged in any way.
    >
    > Richard
    > --
    > RMC,CPA
    >
    >
    > "Norman Jones" <[email protected]> wrote in message news:udro%[email protected]...
    > Hi MysticMarley:
    >
    > Here is a simple example:
    >
    > '===============>>
    > Sub Tester()
    > Dim rng As Range
    >
    > Set rng = ActiveSheet.Range("A1")
    >
    > With rng
    > If .Value > 100 Then
    > 'Do something, e.g.:
    > .Interior.ColorIndex = 3
    > Else
    > 'Do something else, e.g.:
    > .Interior.ColorIndex = 5
    > End If
    > End With
    > End Sub
    >
    > '<<===============
    >
    > ---
    > Regards,
    > Norman
    >
    >
    >
    > "MysticMarley" <[email protected]> wrote in message
    > news:[email protected]...
    > > When my macro starts, I would like for it to reference a value from a cell
    > > then perform one of two actions based upon the value. Is this possible?
    > > Please, explain how.

    >
    >
    >
    >


  6. #6
    R. Choate
    Guest

    Re: Can a Macro contain an IF statement? How?

    Your reply to Norman must be one of those "phantom thank-you's" that just doesn't show up in the same thread. Also, it wasn't you
    who was being called a jerk, it was the other guy who was getting help from Bob, but wasn't satisfied after an hour so he re-posted
    the same problem. I didn't lecture you at all. My note was to Norman, not to you, and it is still valid. Call me whatever you want.

    --
    RMC,CPA


    "MysticMarley" <[email protected]> wrote in message news:[email protected]...
    Maybe you should read the replies before you spit your hatred from your rude
    pie-hole. Unfortunately, I had to get some sleep after my initial post.
    When I arose this morning I read and used Norman's very helpful solution. I
    told him so in the "thank you" reply that I posted... an hour before your
    posted sanctimonious lecture.

    Looks like you're the "jerk", Choate!

    "R. Choate" wrote:

    > Hi Norman,
    >
    > You know, people used to be very gracious when they got help here. Now I almost never even see anybody say thank you for the help
    > they just got. Here you helped this guy hours ago and he didn't even say thank you. I chewed some other guy out who calls himself
    > "Kamakshi" because he was rudely dismissing the help he got from Bob Phillips and just re-posting the problem again just an hour
    > later. Such a jerk. I sent him a link to the Newsgroup netiquette site so he could do some needed reading. Since this guy wouldn't
    > thank you for helping him, I will. Thank you for helping this person and anybody else you help, even when you don't get thanked or
    > acknowledged in any way.
    >
    > Richard
    > --
    > RMC,CPA
    >
    >
    > "Norman Jones" <[email protected]> wrote in message news:udro%[email protected]...
    > Hi MysticMarley:
    >
    > Here is a simple example:
    >
    > '===============>>
    > Sub Tester()
    > Dim rng As Range
    >
    > Set rng = ActiveSheet.Range("A1")
    >
    > With rng
    > If .Value > 100 Then
    > 'Do something, e.g.:
    > .Interior.ColorIndex = 3
    > Else
    > 'Do something else, e.g.:
    > .Interior.ColorIndex = 5
    > End If
    > End With
    > End Sub
    >
    > '<<===============
    >
    > ---
    > Regards,
    > Norman
    >
    >
    >
    > "MysticMarley" <[email protected]> wrote in message
    > news:[email protected]...
    > > When my macro starts, I would like for it to reference a value from a cell
    > > then perform one of two actions based upon the value. Is this possible?
    > > Please, explain how.

    >
    >
    >
    >




  7. #7
    MysticMarley
    Guest

    Re: Can a Macro contain an IF statement? How?

    I accept your apology.

    "R. Choate" wrote:

    > Your reply to Norman must be one of those "phantom thank-you's" that just doesn't show up in the same thread. Also, it wasn't you
    > who was being called a jerk, it was the other guy who was getting help from Bob, but wasn't satisfied after an hour so he re-posted
    > the same problem. I didn't lecture you at all. My note was to Norman, not to you, and it is still valid. Call me whatever you want.
    >
    > --
    > RMC,CPA
    >
    >
    > "MysticMarley" <[email protected]> wrote in message news:[email protected]...
    > Maybe you should read the replies before you spit your hatred from your rude
    > pie-hole. Unfortunately, I had to get some sleep after my initial post.
    > When I arose this morning I read and used Norman's very helpful solution. I
    > told him so in the "thank you" reply that I posted... an hour before your
    > posted sanctimonious lecture.
    >
    > Looks like you're the "jerk", Choate!
    >
    > "R. Choate" wrote:
    >
    > > Hi Norman,
    > >
    > > You know, people used to be very gracious when they got help here. Now I almost never even see anybody say thank you for the help
    > > they just got. Here you helped this guy hours ago and he didn't even say thank you. I chewed some other guy out who calls himself
    > > "Kamakshi" because he was rudely dismissing the help he got from Bob Phillips and just re-posting the problem again just an hour
    > > later. Such a jerk. I sent him a link to the Newsgroup netiquette site so he could do some needed reading. Since this guy wouldn't
    > > thank you for helping him, I will. Thank you for helping this person and anybody else you help, even when you don't get thanked or
    > > acknowledged in any way.
    > >
    > > Richard
    > > --
    > > RMC,CPA
    > >
    > >
    > > "Norman Jones" <[email protected]> wrote in message news:udro%[email protected]...
    > > Hi MysticMarley:
    > >
    > > Here is a simple example:
    > >
    > > '===============>>
    > > Sub Tester()
    > > Dim rng As Range
    > >
    > > Set rng = ActiveSheet.Range("A1")
    > >
    > > With rng
    > > If .Value > 100 Then
    > > 'Do something, e.g.:
    > > .Interior.ColorIndex = 3
    > > Else
    > > 'Do something else, e.g.:
    > > .Interior.ColorIndex = 5
    > > End If
    > > End With
    > > End Sub
    > >
    > > '<<===============
    > >
    > > ---
    > > Regards,
    > > Norman
    > >
    > >
    > >
    > > "MysticMarley" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > When my macro starts, I would like for it to reference a value from a cell
    > > > then perform one of two actions based upon the value. Is this possible?
    > > > Please, explain how.

    > >
    > >
    > >
    > >

    >
    >
    >


  8. #8
    Norman Jones
    Guest

    Re: Can a Macro contain an IF statement? How?

    Hi Richard,

    Speaking purely from a personal perspective, I do not feel it incumbent upon
    a poster to respond to proffered assistance with thanks - which is not to
    say that it is other than rewarding if they do!

    If I choose to respond to a posted question, it is primarily a selfish
    reaction: the pleasure that *I* derive and the concomitant self-learning
    experience considerably outweigh the dubious merits of my response.

    Of course, I must now thank you and I do so, not from any sense of
    obligation, but in appreciation of your sentiments

    As an aside, 'missing' posts can make fools of all of us: nobody, I am sure,
    feels more foolish than I do when, having posted a response to the NG, I
    subsequently discover responses that are not only notably superior but
    significantly pre-date my efforts.I am afraid that 'phantom' or missing
    posts are an integral part of the newsresder experience.

    Thank you again, Richard!


    ---
    Regards,
    Norman



    "R. Choate" <[email protected]> wrote in message
    news:uVur%[email protected]...
    > Hi Norman,
    >
    > You know, people used to be very gracious when they got help here. Now I
    > almost never even see anybody say thank you for the help
    > they just got. Here you helped this guy hours ago and he didn't even say
    > thank you. I chewed some other guy out who calls himself
    > "Kamakshi" because he was rudely dismissing the help he got from Bob
    > Phillips and just re-posting the problem again just an hour
    > later. Such a jerk. I sent him a link to the Newsgroup netiquette site so
    > he could do some needed reading. Since this guy wouldn't
    > thank you for helping him, I will. Thank you for helping this person and
    > anybody else you help, even when you don't get thanked or
    > acknowledged in any way.
    >
    > Richard
    > --
    > RMC,CPA
    >
    >
    > "Norman Jones" <[email protected]> wrote in message
    > news:udro%[email protected]...
    > Hi MysticMarley:
    >
    > Here is a simple example:
    >
    > '===============>>
    > Sub Tester()
    > Dim rng As Range
    >
    > Set rng = ActiveSheet.Range("A1")
    >
    > With rng
    > If .Value > 100 Then
    > 'Do something, e.g.:
    > .Interior.ColorIndex = 3
    > Else
    > 'Do something else, e.g.:
    > .Interior.ColorIndex = 5
    > End If
    > End With
    > End Sub
    >
    > '<<===============
    >
    > ---
    > Regards,
    > Norman
    >
    >
    >
    > "MysticMarley" <[email protected]> wrote in message
    > news:[email protected]...
    >> When my macro starts, I would like for it to reference a value from a
    >> cell
    >> then perform one of two actions based upon the value. Is this possible?
    >> Please, explain how.

    >
    >
    >




+ 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