ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   <1000 (https://www.excelbanter.com/excel-programming/436053-1000.html)

Doug

<1000
 
The program below looks at a cell to see if the cell is =5000 and if it is
adds a cost to another set of cells on the sheet. All works well until I have
an entry less than 1000. At this point it adds the cost anyway when it should
not. I need to know how to make this work when below 1000.

Thanks,
Doug

If ChkGenset.Value = False Then
Sheets("Tank").Unprotect Password:="benjamin"
Sheets("TankCalcs").Unprotect Password:="benjamin"
Sheets("TankCalcs").Range("I22").Value = ""
Sheets("Tank").Range("C13").Value = ""
Sheets("Tank").Range("F56").Value = ""
Sheets("Tank").Range("G56").Value = ""
ChkWP.Enabled = True
ChkSA.Enabled = True
Sheets("Tank").Protect Password:="benjamin"
Sheets("TankCalcs").Protect Password:="benjamin"

Else: Sheets("Tank").Unprotect Password:="benjamin"
Sheets("TankCalcs").Unprotect Password:="benjamin"
Sheets("TankCalcs").Range("I22").Value = "3"
Sheets("Tank").Range("C13").Value = Sheets("TankCalcs").Range("J30")
ChkWP.Enabled = False
ChkSA.Enabled = False
Sheets("Tank").Range("F56").Value = ""
Sheets("Tank").Range("G56").Value = ""
'looks at Total Gal of tank and if equal to or greater than 5000gal
it automatically adds the cost and weight of a manhole
If Sheets("Tank").Range("C7").Value = "5000" Then
Sheets("Tank").Range("F56").Value =
Sheets("TankCalcs").Range("H2").Value
Sheets("Tank").Range("G56").Value =
Sheets("TankCalcs").Range("I2").Value
End If
Sheets("Tank").Protect Password:="benjamin"
Sheets("TankCalcs").Protect Password:="benjamin"
End If

Barb Reinhardt

<1000
 
Try this with a few tweaks.

Option Explicit
Sub Test()
Dim myTank As Worksheet
Dim myTankCalcs As Worksheet

Set myTank = Worksheets("Tank")
Set myTankCalc = Worksheets("TankCalcs")

If ChkGenset.Value = False Then
myTank.Unprotect Password:="benjamin"
myTankCalcs.Unprotect Password:="benjamin"
myTankCalcs.Range("I22").Value = ""
myTank.Range("C13").Value = ""
myTank.Range("F56").Value = ""
myTank.Range("G56").Value = ""
ChkWP.Enabled = True
ChkSA.Enabled = True
myTank.Protect Password:="benjamin"
myTankCalcs.Protect Password:="benjamin"

Else:
myTank.Unprotect Password:="benjamin"
myTankCalcs.Unprotect Password:="benjamin"
myTankCalcs.Range("I22").Value = "3"
myTank.Range("C13").Value = myTankCalcs.Range("J30")
ChkWP.Enabled = False
ChkSA.Enabled = False
myTank.Range("F56").Value = ""
myTank.Range("G56").Value = ""
'looks at Total Gal of tank and if equal to or greater than 5000gal
'it automatically adds the cost and weight of a manhole
If myTank.Range("C7").Value = 5000 Then 'Changed from "5000"
myTank.Range("F56").Value = myTankCalcs.Range("H2").Value
myTank.Range("G56").Value = myTankCalcs.Range("I2").Value
End If
myTank.Protect Password:="benjamin"
myTankCalcs.Protect Password:="benjamin"
End If
End Sub
--
HTH,

Barb Reinhardt



"Doug" wrote:

The program below looks at a cell to see if the cell is =5000 and if it is
adds a cost to another set of cells on the sheet. All works well until I have
an entry less than 1000. At this point it adds the cost anyway when it should
not. I need to know how to make this work when below 1000.

Thanks,
Doug

If ChkGenset.Value = False Then
Sheets("Tank").Unprotect Password:="benjamin"
Sheets("TankCalcs").Unprotect Password:="benjamin"
Sheets("TankCalcs").Range("I22").Value = ""
Sheets("Tank").Range("C13").Value = ""
Sheets("Tank").Range("F56").Value = ""
Sheets("Tank").Range("G56").Value = ""
ChkWP.Enabled = True
ChkSA.Enabled = True
Sheets("Tank").Protect Password:="benjamin"
Sheets("TankCalcs").Protect Password:="benjamin"

Else: Sheets("Tank").Unprotect Password:="benjamin"
Sheets("TankCalcs").Unprotect Password:="benjamin"
Sheets("TankCalcs").Range("I22").Value = "3"
Sheets("Tank").Range("C13").Value = Sheets("TankCalcs").Range("J30")
ChkWP.Enabled = False
ChkSA.Enabled = False
Sheets("Tank").Range("F56").Value = ""
Sheets("Tank").Range("G56").Value = ""
'looks at Total Gal of tank and if equal to or greater than 5000gal
it automatically adds the cost and weight of a manhole
If Sheets("Tank").Range("C7").Value = "5000" Then
Sheets("Tank").Range("F56").Value =
Sheets("TankCalcs").Range("H2").Value
Sheets("Tank").Range("G56").Value =
Sheets("TankCalcs").Range("I2").Value
End If
Sheets("Tank").Protect Password:="benjamin"
Sheets("TankCalcs").Protect Password:="benjamin"
End If


Doug

<1000
 
Barb,
Thanks for your suggestion. I reviewed the changes you made and saw that you
removed the quotation marks from the 5000 and tried that first rather than
making all the other changes, it worked. I guess I thought since it was a
number referenced in a cell it had to have the quotation marks.

Thanks,
Doug

"Barb Reinhardt" wrote:

Try this with a few tweaks.

Option Explicit
Sub Test()
Dim myTank As Worksheet
Dim myTankCalcs As Worksheet

Set myTank = Worksheets("Tank")
Set myTankCalc = Worksheets("TankCalcs")

If ChkGenset.Value = False Then
myTank.Unprotect Password:="benjamin"
myTankCalcs.Unprotect Password:="benjamin"
myTankCalcs.Range("I22").Value = ""
myTank.Range("C13").Value = ""
myTank.Range("F56").Value = ""
myTank.Range("G56").Value = ""
ChkWP.Enabled = True
ChkSA.Enabled = True
myTank.Protect Password:="benjamin"
myTankCalcs.Protect Password:="benjamin"

Else:
myTank.Unprotect Password:="benjamin"
myTankCalcs.Unprotect Password:="benjamin"
myTankCalcs.Range("I22").Value = "3"
myTank.Range("C13").Value = myTankCalcs.Range("J30")
ChkWP.Enabled = False
ChkSA.Enabled = False
myTank.Range("F56").Value = ""
myTank.Range("G56").Value = ""
'looks at Total Gal of tank and if equal to or greater than 5000gal
'it automatically adds the cost and weight of a manhole
If myTank.Range("C7").Value = 5000 Then 'Changed from "5000"
myTank.Range("F56").Value = myTankCalcs.Range("H2").Value
myTank.Range("G56").Value = myTankCalcs.Range("I2").Value
End If
myTank.Protect Password:="benjamin"
myTankCalcs.Protect Password:="benjamin"
End If
End Sub
--
HTH,

Barb Reinhardt



"Doug" wrote:

The program below looks at a cell to see if the cell is =5000 and if it is
adds a cost to another set of cells on the sheet. All works well until I have
an entry less than 1000. At this point it adds the cost anyway when it should
not. I need to know how to make this work when below 1000.

Thanks,
Doug

If ChkGenset.Value = False Then
Sheets("Tank").Unprotect Password:="benjamin"
Sheets("TankCalcs").Unprotect Password:="benjamin"
Sheets("TankCalcs").Range("I22").Value = ""
Sheets("Tank").Range("C13").Value = ""
Sheets("Tank").Range("F56").Value = ""
Sheets("Tank").Range("G56").Value = ""
ChkWP.Enabled = True
ChkSA.Enabled = True
Sheets("Tank").Protect Password:="benjamin"
Sheets("TankCalcs").Protect Password:="benjamin"

Else: Sheets("Tank").Unprotect Password:="benjamin"
Sheets("TankCalcs").Unprotect Password:="benjamin"
Sheets("TankCalcs").Range("I22").Value = "3"
Sheets("Tank").Range("C13").Value = Sheets("TankCalcs").Range("J30")
ChkWP.Enabled = False
ChkSA.Enabled = False
Sheets("Tank").Range("F56").Value = ""
Sheets("Tank").Range("G56").Value = ""
'looks at Total Gal of tank and if equal to or greater than 5000gal
it automatically adds the cost and weight of a manhole
If Sheets("Tank").Range("C7").Value = "5000" Then
Sheets("Tank").Range("F56").Value =
Sheets("TankCalcs").Range("H2").Value
Sheets("Tank").Range("G56").Value =
Sheets("TankCalcs").Range("I2").Value
End If
Sheets("Tank").Protect Password:="benjamin"
Sheets("TankCalcs").Protect Password:="benjamin"
End If



All times are GMT +1. The time now is 02:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com