Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    May 2005
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    set decimals to one place or two base on condition (excel 2002)

    Hi everyone,

    I have a worksheet here which has threes columns which change depending on a condition
    the condition is
    n2 or Co2. sO I HAVE THE FOLLOWING macro. which is activated by a button. For some reason though my macro does not work and I cant find the problem and thought someone else might be able to??


    Sub DecimalSetPropScheduleCO2N2()
    ' Sets Col.s M,O,P decimals for 1st Prop Schedule when CO2Energized or N2Energized.
    If Range("CO2Energized") And Range("DecimalSettingCO2N2") <> "CO2" Then
    ' Sets Col.M to 2 decimals and Col.s O,P to 1 for all 5 Schedules when CO2Energized.
    Range("DecimalCO2N2RateRange").NumberFormat = "0.00"
    Range("DecimalCO2N2RateRange2").NumberFormat = "0.00"
    Range("DecimalCO2N2RateRange3").NumberFormat = "0.00"
    Range("DecimalCO2N2RateRange4").NumberFormat = "0.00"
    Range("DecimalCO2N2RateRange5").NumberFormat = "0.00"
    Range("DecimalCO2N2RateRange6").NumberFormat = "0.00"
    Range("DecimalCO2N2CumStageRange").NumberFormat = "0.0"
    Range("DecimalCO2N2CumStageRange2").NumberFormat = "0.0"
    Range("DecimalCO2N2CumStageRange3").NumberFormat = "0.0"
    Range("DecimalCO2N2CumStageRange4").NumberFormat = "0.0"
    Range("DecimalCO2N2CumStageRange5").NumberFormat = "0.0"
    Range("DecimalCO2N2CumStageRange6").NumberFormat = "0.0"
    Range("DecimalSettingCO2N2") = "CO2"
    ElseIf Range("N2Energized") And Range("DecimalSettingCO2N2") <> "N2" Then
    ' Sets Col.M to 0 decimals and Col.s O,P to 0 for 1st Schedule when N2En.
    Range("DecimalCO2N2RateRange").NumberFormat = "0"
    Range("DecimalCO2N2RateRange2").NumberFormat = "0"
    Range("DecimalCO2N2RateRange3").NumberFormat = "0"
    Range("DecimalCO2N2RateRange4").NumberFormat = "0"
    Range("DecimalCO2N2RateRange5").NumberFormat = "0"
    Range("DecimalCO2N2RateRange6").NumberFormat = "0"
    Range("DecimalCO2N2CumStageRange").NumberFormat = "0"
    Range("DecimalCO2N2CumStageRange2").NumberFormat = "0"
    Range("DecimalCO2N2CumStageRange3").NumberFormat = "0"
    Range("DecimalCO2N2CumStageRange4").NumberFormat = "0"
    Range("DecimalCO2N2CumStageRange5").NumberFormat = "0"
    Range("DecimalCO2N2CumStageRange6").NumberFormat = "0"
    Range("DecimalSettingCO2N2") = "N2"
    End If
    End Sub

    Thank you

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: set decimals to one place or two base on condition (excel 2002)

    The condition

    If Range("CO2Energized") And Range("DecimalSettingCO2N2") <> "CO2" Then

    looks strange. Does CO2Energized contain TRUE or FALSE?

  3. #3
    2 Star Lounger
    Join Date
    May 2005
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: set decimals to one place or two base on condition (excel 2002)

    yes it contains true or false

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: set decimals to one place or two base on condition (excel 2002)

    Try single-stepping through the macro: click somewhere in the macro, then press F8. You'll be able to inspect the value of ranges etc. by hovering the mouse pointer over them in the code.
    Each subsequent F8 will execute one step, so you can see which part of the code gets executed.

  5. #5
    2 Star Lounger
    Join Date
    May 2005
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: set decimals to one place or two base on condition (excel 2002)

    thanks Hans , I found the problem
    it was the true false not properly working

    thank you

Posting Permissions

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