PDA

View Full Version : Solved: Why won't this work?



Djblois
03-22-2007, 08:13 AM
dim WhseProd as boolean

WhseProd = true

if whseprod then
'My code
end if


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?

moa
03-22-2007, 08:16 AM
WhseProd may need to be a global variable set in a standard module.

Djblois
03-22-2007, 08:17 AM
I do set it as public, I just typed in that code for expediency.

Djblois
03-22-2007, 08:17 AM
oh and by the way that is the quickest response I think I have ever had. lol

moa
03-22-2007, 08:18 AM
What doesn't work then? Is there an error message?

lucas
03-22-2007, 08:18 AM
might try this Daniel
If whseprod = true Then
'My code
End If

Zack Barresse
03-22-2007, 08:19 AM
If your routine is losing focus, the variable will be lost after run-time. Check out the Static method if that is the case.

moa
03-22-2007, 08:24 AM
It's like a feeding frenzy

Djblois
03-22-2007, 08:33 AM
what do you mean the static method?

Zack Barresse
03-22-2007, 08:46 AM
Did you look it up??

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

Bob Phillips
03-22-2007, 08:46 AM
Static variable_name As Boolean

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

Bob Phillips
03-22-2007, 08:46 AM
BTW, static must be declared within a procedure, not outwith.

Zack Barresse
03-22-2007, 09:08 AM
Or in a class module.

Djblois
03-22-2007, 11:11 AM
thank you all for your help, I figured out another way to accomplish it.

Zack Barresse
03-26-2007, 09:09 AM
So, how about posting it? :)

Djblois
03-26-2007, 09:21 AM
No Problem here:

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

Bob Phillips
03-26-2007, 09:41 AM
Simplify it



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

Djblois
03-26-2007, 09:44 AM
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.

Zack Barresse
03-26-2007, 09:51 AM
What do you mean, "different spots"?

Djblois
03-26-2007, 09:52 AM
Different spots in the code. I do the test at the beginning then near the end I check to see which code to run.