Consulting

Results 1 to 20 of 20

Thread: Solved: Why won't this work?

  1. #1
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location

    Solved: Why won't this work?

    [VBA]
    dim WhseProd as boolean

    WhseProd = true

    if whseprod then
    'My code
    end if
    [/VBA]

    I am using the code to check if there is something in a particular cell and then later decide what to do so that if it is whseprod it would do one thing if it is not it would do something else?

  2. #2
    VBAX Contributor moa's Avatar
    Joined
    Nov 2006
    Posts
    177
    Location
    WhseProd may need to be a global variable set in a standard module.
    Glen

  3. #3
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    I do set it as public, I just typed in that code for expediency.

  4. #4
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    oh and by the way that is the quickest response I think I have ever had. lol

  5. #5
    VBAX Contributor moa's Avatar
    Joined
    Nov 2006
    Posts
    177
    Location
    What doesn't work then? Is there an error message?
    Glen

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    might try this Daniel
    [VBA]If whseprod = true Then
    'My code
    End If [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    If your routine is losing focus, the variable will be lost after run-time. Check out the Static method if that is the case.

  8. #8
    VBAX Contributor moa's Avatar
    Joined
    Nov 2006
    Posts
    177
    Location
    It's like a feeding frenzy
    Glen

  9. #9
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    what do you mean the static method?

  10. #10
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Did you look it up??

    Also look at the GetSetting and SaveSetting methods. Think about storing values in cell(s) as well.

  11. #11
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Static variable_name As Boolean

    but I would venture that more info is what is really needed.

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    BTW, static must be declared within a procedure, not outwith.

  13. #13
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Or in a class module.

  14. #14
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    thank you all for your help, I figured out another way to accomplish it.

  15. #15
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    So, how about posting it?

  16. #16
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    No Problem here:

    [VBA]Set findString = Range("A8").Find(What:="REGN*")
    If findString Is Nothing Then
    Set findString = Range("B7").Find(What:="EQUI*")
    If findString Is Nothing Then
    i = 1
    Else
    i = 2
    End If
    Else
    Set findString = Range("B7").Find(What:="EQUI*")
    If findString Is Nothing Then
    i = 3
    Else
    i = 4
    End If
    End If

    If i = 4 Then
    Range("A1").FormulaR1C1 = "Whse Region"
    Range("B1").FormulaR1C1 = "Equiv Code"
    ActiveSheet.PageSetup.CenterHeader = "&""Arial,Bold""&14Reorder Report - Warehouse Region/ Equivalency Group"
    ElseIf i = 3 Then
    Range("A1").FormulaR1C1 = "Whse Region"
    Range("B1").FormulaR1C1 = "Item Code"
    ActiveSheet.PageSetup.CenterHeader = "&""Arial,Bold""&14Reorder Report - Warehouse Region/ Product"
    ElseIf i = 2 Then
    Range("A1").FormulaR1C1 = "Whse"
    Range("B1").FormulaR1C1 = "Equiv Code"
    ActiveSheet.PageSetup.CenterHeader = "&""Arial,Bold""&14Reorder Report - Warehouse/ Equivalency Group"
    ElseIf i = 1 Then
    Range("A1").FormulaR1C1 = "Whse"
    Range("B1").FormulaR1C1 = "Item Code"
    ActiveSheet.PageSetup.CenterHeader = "&""Arial,Bold""&14Reorder Report - Warehouse/ Product"
    End If[/VBA]

  17. #17
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Simplify it

    [vba]

    Set findString = Range("A8").Find(What:="REGN*")
    If findString Is Nothing Then
    Set findString = Range("B7").Find(What:="EQUI*")
    If findString Is Nothing Then
    Range("A1").FormulaR1C1 = "Whse"
    Range("B1").FormulaR1C1 = "Item Code"
    ActiveSheet.PageSetup.CenterHeader = "&""Arial,Bold""&14Reorder Report - Warehouse/ Product"
    Else
    Range("A1").FormulaR1C1 = "Whse"
    Range("B1").FormulaR1C1 = "Equiv Code"
    ActiveSheet.PageSetup.CenterHeader = "&""Arial,Bold""&14Reorder Report - Warehouse/ Equivalency Group"
    End If
    Else
    Set findString = Range("B7").Find(What:="EQUI*")
    If findString Is Nothing Then
    Range("A1").FormulaR1C1 = "Whse Region"
    Range("B1").FormulaR1C1 = "Item Code"
    ActiveSheet.PageSetup.CenterHeader = "&""Arial,Bold""&14Reorder Report - Warehouse Region/ Product"
    Else
    Range("A1").FormulaR1C1 = "Whse Region"
    Range("B1").FormulaR1C1 = "Equiv Code"
    ActiveSheet.PageSetup.CenterHeader = "&""Arial,Bold""&14Reorder Report - Warehouse Region/ Equivalency Group"
    End If
    End If
    [/vba]

  18. #18
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    The reason why I don't do that is they are actually in two different spots in my code or I would have done it that way but thank you.

  19. #19
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    What do you mean, "different spots"?

  20. #20
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    Different spots in the code. I do the test at the beginning then near the end I check to see which code to run.

Posting Permissions

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