thunder_anger
Board Regular
- Joined
- Sep 27, 2009
- Messages
- 206
<TABLE style="WIDTH: 108pt; BORDER-COLLAPSE: collapse" dir=rtl border=0 cellSpacing=0 cellPadding=0 width=144><COLGROUP><COL style="WIDTH: 54pt" span=2 width=72><TBODY><TR style="HEIGHT: 14.25pt" height=19><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: #8db4e3; WIDTH: 54pt; HEIGHT: 14.25pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" dir=ltr class=xl63 height=19 width=72 align=left>Item</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: #8db4e3; WIDTH: 54pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" dir=ltr class=xl63 width=72 align=left>Stock</TD></TR><TR style="HEIGHT: 14.25pt" height=19><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: #8db4e3; HEIGHT: 14.25pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" dir=ltr class=xl63 height=19 align=left>Tea</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" dir=ltr class=xl64 align=right>30</TD></TR><TR style="HEIGHT: 14.25pt" height=19><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: #8db4e3; HEIGHT: 14.25pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" dir=ltr class=xl63 height=19 align=left>Coffee</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" dir=ltr class=xl64 align=right>100</TD></TR><TR style="HEIGHT: 14.25pt" height=19><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: #8db4e3; HEIGHT: 14.25pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" dir=ltr class=xl63 height=19 align=left>Gum</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" dir=ltr class=xl64 align=right>125</TD></TR><TR style="HEIGHT: 14.25pt" height=19><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: #8db4e3; HEIGHT: 14.25pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" dir=ltr class=xl63 height=19 align=left>Water</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" dir=ltr class=xl64 align=right>400</TD></TR></TBODY></TABLE>
in the above example i made this macro not to allow user to delete or edit any cell that contans an item that have a stock so if he tries to delete the word tea a message box will appear saying that this item can not be deleted because the stock is greater than zero
and this code for the sheet1 change event
but i discovered that i can edit the cells
any one help me not to allow users edit or delete an item unless stock is 0
in the above example i made this macro not to allow user to delete or edit any cell that contans an item that have a stock so if he tries to delete the word tea a message box will appear saying that this item can not be deleted because the stock is greater than zero
Code:
Sub Hos()
Dim StRng As Range
Dim StRngC As Range
Set StRng = Sheet1.Range("A6:A8")
For Each StRngC In StRng
If StRngC.Value = "" And StRngC.Offset(0, 1) > 0 Then
MsgBox "you can not delete the item! stock greater than (0)"
Application.Undo
End If
Next StRngC
End Sub
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range("A6:A8"), Target) Is Nothing Then Call Hos
End Sub
but i discovered that i can edit the cells
any one help me not to allow users edit or delete an item unless stock is 0
Last edited: