This code works perfect I want to expand on my ZONES, right now there is 5 and I want to expand to 6. The error I get is " unable to get index property of the worksheetfunction class". Im just not sure what area I need to look at to adjust the code to see the additional zone. Thanks
Private Sub Worksheet_Change(ByVal Target As Range)
' STILL NEED PROTECTION ROUTINE FOR J-M
Dim DataRng As Range, DescRng As Range, QuanRng As Range
Dim Desc As String, Location As String, MyPassword As String
Dim Qty As Long, Zone As Long
Static BigQtyPwd As String
Location = [D21]
MyPassword = "ABC" ' // ***** PUT YOUR PASSWORD HERE ***** //
Set DataRng = Worksheets(Location).[A1:AD93]
Set DescRng = Worksheets(Location).[B1:B93]
Set QuanRng = Worksheets(Location).[A2:i2]
On Error GoTo Xit
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.EnableEvents = False
' // If the changed cell is not in the range of A25:D40 then go down //
' // to the next check and see if it is cell D20 or cell G21. //
If Not Intersect(Target, Range("A26:A35", "D26:D35")) Is Nothing Then
' // Seed Install & Rental rates if there is a quantity and a description. //
If (Range("A" & Target.Row) > 0) And (Len(Range("D" & Target.Row)) > 0) Then
Qty = Range("A" & Target.Row)
Desc = Range("D" & Target.Row)
Zone = [G21]
' // Get password, & price, if quantity is greater than 2499 and B not a custom category. //
' // <<<<<THIS below with work to trying I?m area the is>>>>>
If Range("B" & Target.Row) = "DAMAGED" Or Range("B" & Target.Row) = "MISSING" Then
Range("H" & Target.Row) = Application.WorksheetFunction.Index(DataRng, Application.WorksheetFunction.Match(Desc, DescRng, 0), 39)
ElseIf Range("B" & Target.Row) = "PURCHASE" Then
Range("H" & Target.Row) = Application.WorksheetFunction.Index(DataRng, Application.WorksheetFunction.Match(Desc, DescRng, 0), 40)
ElseIf (Range("B" & Target.Row) = "REMOVE & RELOCATE") And Right(Range("D" & Target.Row), 10) = "SWING GATE" Then
Range("H" & Target.Row) = Application.WorksheetFunction.Index(DataRng, Application.WorksheetFunction.Match(Desc, DescRng, 0), Application.WorksheetFunction.Match(Qty, QuanRng, 1) + ((Zone - 1) * 9)) - 25
ElseIf (Range("B" & Target.Row) = "REMOVE & RELOCATE") And Right(Range("D" & Target.Row), 26) = "CHAIN LINK & POUNDED POSTS" Then
Range("H" & Target.Row) = Application.WorksheetFunction.Index(DataRng, Application.WorksheetFunction.Match(Desc, DescRng, 0), Application.WorksheetFunction.Match(Qty, QuanRng, 1) + ((Zone - 1) * 9)) - 0.1
ElseIf (Range("B" & Target.Row) = "REMOVE & RELOCATE") And Right(Range("D" & Target.Row), 26) = "6' PANELS WITH STANDS" Then
Range("H" & Target.Row) = 1.95
ElseIf (Range("B" & Target.Row) = "REINSTALL") And Right(Range("D" & Target.Row), 26) = "6' PANELS WITH STANDS" Then
Range("H" & Target.Row) = 1.95
ElseIf (Range("B" & Target.Row) = "REINSTALL") And Right(Range("D" & Target.Row), 29) = "6' CHAIN LINK & POUNDED POSTS" Then
Range("H" & Target.Row) = 2.25
ElseIf (Range("B" & Target.Row) = "REMOVE & RELOCATE") And Right(Range("D" & Target.Row), 26) = "8' PANELS WITH STANDS" Then
Range("H" & Target.Row) = 2.75
ElseIf (Range("B" & Target.Row) = "REMOVE & RELOCATE") And Left(Range("D" & Target.Row), 13) = "6' WINDSCREEN" Then
Range("H" & Target.Row) = 1.75
ElseIf (Range("B" & Target.Row) = "REMOVE & RELOCATE") And Left(Range("D" & Target.Row), 13) = "8' WINDSCREEN" Then
Range("H" & Target.Row) = 2.75
ElseIf (Range("B" & Target.Row) = "REMOVE & RELOCATE") And Left(Range("D" & Target.Row), 9) = "SAND BAGS" Then
Range("H" & Target.Row) = 3
ElseIf (Range("B" & Target.Row) = "GENERAL REPAIR" Or Range("B" & Target.Row) = "RETIE") And Left(Range("D" & Target.Row), 29) = "6' CHAIN LINK & POUNDED POSTS" Then
Range("H" & Target.Row) = 1.65
ElseIf (Range("B" & Target.Row) = "GENERAL REPAIR" Or Range("B" & Target.Row) = "RETIE") And Left(Range("D" & Target.Row), 29) = "8' CHAIN LINK & POUNDED POSTS" Then
Range("H" & Target.Row) = 1.95
ElseIf (Range("B" & Target.Row) = "DAMAGED - REMOVE & REPLACE") Then
Range("H" & Target.Row) = Application.WorksheetFunction.Index(DataRng, Application.WorksheetFunction.Match(Desc, DescRng, 0), Application.WorksheetFunction.Match(Qty, QuanRng, 1) + ((Zone - 1) * 9)) + Application.WorksheetFunction.Index(DataRng, Application.WorksheetFunction.Match(Desc, DescRng, 0), 39)
ElseIf (Range("B" & Target.Row) = "FULL PULL") Or (Range("B" & Target.Row) = "PART PULL") Then
Range("H" & Target.Row).ClearContents
ElseIf (Len(Desc) <> 0) And (Qty >= 20000) Then
If (UserForm1.TextBox1.Text <> MyPassword) And (PasswordIsVerified = False) Then
UserForm1.Show
If (UserForm1.TextBox1.Text = MyPassword) Then
PasswordIsVerified = True
Range("G" & Target.Row) = Application.InputBox("Enter rate", "Large Quantity Custom Rate", , , , , , 1)
Else
MsgBox "Sorry, that was incorrect. Exiting."
Range("A" & Target.Row) = vbNullString
Range("H" & Target.Row) = vbNullString
GoTo Xit
End If
Else
Range("H" & Target.Row) = Application.InputBox("Enter rate", "Large Quantity Custom Rate", , , , , , 1)
End If
Else
Range("H" & Target.Row) = Application.WorksheetFunction.Index(DataRng, Application.WorksheetFunction.Match(Desc, DescRng, 0), Application.WorksheetFunction.Match(Qty, QuanRng, 1) + ((Zone - 1) * 9))
End If
' Seed the Rantal rate here. //
ElseIf (UserForm1.TextBox1.Text <> MyPassword) Then
' // If either the quantity or description //
' // is null set G and I to null as well. //
Range("H" & Target.Row) = vbNullString
ElseIf (Range("B" & Target.Row) = "FULL PULL") Or (Range("B" & Target.Row) = "DAMAGED") Or (Range("B" & Target.Row) = "BRING EXTRA") Then Range("H" & Target.Row).ClearContents
End If
ElseIf Not Intersect(Target, Range("D21", "G21")) Is Nothing Then
' // If Area or Zone changes then recalc the Inst&Rental values //
Zone = [G21]: Location = [D21]
For i = 38 To 39
If (Range("A" & i) > 0) And (Len(Range("D" & i)) > 0) Then
Qty = Range("A" & i)
Desc = Range("D" & i)
If (Qty < 20000) Then
Range("H" & i) = Application.WorksheetFunction.Index(DataRng, Application.WorksheetFunction.Match(Desc, DescRng, 0), Application.WorksheetFunction.Match(Qty, QuanRng, 1) + ((Zone - 1) * 9))
End If
End If
Next i
ElseIf Not Intersect(Target, Range("G26:G35", "I26:I35")) Is Nothing Then
' // If any attempt is made to directly change the Inst+Rmvl or Rental rates //
ElseIf Not Intersect(Target, Range("B25:B34")) Is Nothing Then
' // Custom pricing in these cases. //
End If
Xit:
' Cleanup here. //
If Err.Number <> 0 Then
ErrMsg = "Error:" & str(Err.Number) & " was generated " _
& Err.Source & Chr(13) & Err.Description
MsgBox ErrMsg, , "Error", Err.HelpFile, Err.HelpContext
MsgBox "Processing Terminated."
Err.Clear
End If
For i = 25 To 27
If (Len(Range("A" & i)) = 0) Or (Len(Range("D" & i)) = 0) Then
Range("H" & i) = vbNullString
End If
Next i
' // Zap variables. //
Set DataRng = Nothing
Set DescRng = Nothing
Set HeadRng = Nothing
Application.Calculation = xlCalculationAutomatic
If Not Intersect(ActiveCell, [A26:I35]) Is Nothing Then
Application.EnableEvents = False
ActiveSheet.Unprotect ("as")
Range("K7").Formula = "=NOW()"
ActiveSheet.Protect ("as")
End If
ActiveSheet.Protect ("as")
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.CutCopyMode = False
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
' STILL NEED PROTECTION ROUTINE FOR J-M
Dim DataRng As Range, DescRng As Range, QuanRng As Range
Dim Desc As String, Location As String, MyPassword As String
Dim Qty As Long, Zone As Long
Static BigQtyPwd As String
Location = [D21]
MyPassword = "ABC" ' // ***** PUT YOUR PASSWORD HERE ***** //
Set DataRng = Worksheets(Location).[A1:AD93]
Set DescRng = Worksheets(Location).[B1:B93]
Set QuanRng = Worksheets(Location).[A2:i2]
On Error GoTo Xit
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.EnableEvents = False
' // If the changed cell is not in the range of A25:D40 then go down //
' // to the next check and see if it is cell D20 or cell G21. //
If Not Intersect(Target, Range("A26:A35", "D26:D35")) Is Nothing Then
' // Seed Install & Rental rates if there is a quantity and a description. //
If (Range("A" & Target.Row) > 0) And (Len(Range("D" & Target.Row)) > 0) Then
Qty = Range("A" & Target.Row)
Desc = Range("D" & Target.Row)
Zone = [G21]
' // Get password, & price, if quantity is greater than 2499 and B not a custom category. //
' // <<<<<THIS below with work to trying I?m area the is>>>>>
If Range("B" & Target.Row) = "DAMAGED" Or Range("B" & Target.Row) = "MISSING" Then
Range("H" & Target.Row) = Application.WorksheetFunction.Index(DataRng, Application.WorksheetFunction.Match(Desc, DescRng, 0), 39)
ElseIf Range("B" & Target.Row) = "PURCHASE" Then
Range("H" & Target.Row) = Application.WorksheetFunction.Index(DataRng, Application.WorksheetFunction.Match(Desc, DescRng, 0), 40)
ElseIf (Range("B" & Target.Row) = "REMOVE & RELOCATE") And Right(Range("D" & Target.Row), 10) = "SWING GATE" Then
Range("H" & Target.Row) = Application.WorksheetFunction.Index(DataRng, Application.WorksheetFunction.Match(Desc, DescRng, 0), Application.WorksheetFunction.Match(Qty, QuanRng, 1) + ((Zone - 1) * 9)) - 25
ElseIf (Range("B" & Target.Row) = "REMOVE & RELOCATE") And Right(Range("D" & Target.Row), 26) = "CHAIN LINK & POUNDED POSTS" Then
Range("H" & Target.Row) = Application.WorksheetFunction.Index(DataRng, Application.WorksheetFunction.Match(Desc, DescRng, 0), Application.WorksheetFunction.Match(Qty, QuanRng, 1) + ((Zone - 1) * 9)) - 0.1
ElseIf (Range("B" & Target.Row) = "REMOVE & RELOCATE") And Right(Range("D" & Target.Row), 26) = "6' PANELS WITH STANDS" Then
Range("H" & Target.Row) = 1.95
ElseIf (Range("B" & Target.Row) = "REINSTALL") And Right(Range("D" & Target.Row), 26) = "6' PANELS WITH STANDS" Then
Range("H" & Target.Row) = 1.95
ElseIf (Range("B" & Target.Row) = "REINSTALL") And Right(Range("D" & Target.Row), 29) = "6' CHAIN LINK & POUNDED POSTS" Then
Range("H" & Target.Row) = 2.25
ElseIf (Range("B" & Target.Row) = "REMOVE & RELOCATE") And Right(Range("D" & Target.Row), 26) = "8' PANELS WITH STANDS" Then
Range("H" & Target.Row) = 2.75
ElseIf (Range("B" & Target.Row) = "REMOVE & RELOCATE") And Left(Range("D" & Target.Row), 13) = "6' WINDSCREEN" Then
Range("H" & Target.Row) = 1.75
ElseIf (Range("B" & Target.Row) = "REMOVE & RELOCATE") And Left(Range("D" & Target.Row), 13) = "8' WINDSCREEN" Then
Range("H" & Target.Row) = 2.75
ElseIf (Range("B" & Target.Row) = "REMOVE & RELOCATE") And Left(Range("D" & Target.Row), 9) = "SAND BAGS" Then
Range("H" & Target.Row) = 3
ElseIf (Range("B" & Target.Row) = "GENERAL REPAIR" Or Range("B" & Target.Row) = "RETIE") And Left(Range("D" & Target.Row), 29) = "6' CHAIN LINK & POUNDED POSTS" Then
Range("H" & Target.Row) = 1.65
ElseIf (Range("B" & Target.Row) = "GENERAL REPAIR" Or Range("B" & Target.Row) = "RETIE") And Left(Range("D" & Target.Row), 29) = "8' CHAIN LINK & POUNDED POSTS" Then
Range("H" & Target.Row) = 1.95
ElseIf (Range("B" & Target.Row) = "DAMAGED - REMOVE & REPLACE") Then
Range("H" & Target.Row) = Application.WorksheetFunction.Index(DataRng, Application.WorksheetFunction.Match(Desc, DescRng, 0), Application.WorksheetFunction.Match(Qty, QuanRng, 1) + ((Zone - 1) * 9)) + Application.WorksheetFunction.Index(DataRng, Application.WorksheetFunction.Match(Desc, DescRng, 0), 39)
ElseIf (Range("B" & Target.Row) = "FULL PULL") Or (Range("B" & Target.Row) = "PART PULL") Then
Range("H" & Target.Row).ClearContents
ElseIf (Len(Desc) <> 0) And (Qty >= 20000) Then
If (UserForm1.TextBox1.Text <> MyPassword) And (PasswordIsVerified = False) Then
UserForm1.Show
If (UserForm1.TextBox1.Text = MyPassword) Then
PasswordIsVerified = True
Range("G" & Target.Row) = Application.InputBox("Enter rate", "Large Quantity Custom Rate", , , , , , 1)
Else
MsgBox "Sorry, that was incorrect. Exiting."
Range("A" & Target.Row) = vbNullString
Range("H" & Target.Row) = vbNullString
GoTo Xit
End If
Else
Range("H" & Target.Row) = Application.InputBox("Enter rate", "Large Quantity Custom Rate", , , , , , 1)
End If
Else
Range("H" & Target.Row) = Application.WorksheetFunction.Index(DataRng, Application.WorksheetFunction.Match(Desc, DescRng, 0), Application.WorksheetFunction.Match(Qty, QuanRng, 1) + ((Zone - 1) * 9))
End If
' Seed the Rantal rate here. //
ElseIf (UserForm1.TextBox1.Text <> MyPassword) Then
' // If either the quantity or description //
' // is null set G and I to null as well. //
Range("H" & Target.Row) = vbNullString
ElseIf (Range("B" & Target.Row) = "FULL PULL") Or (Range("B" & Target.Row) = "DAMAGED") Or (Range("B" & Target.Row) = "BRING EXTRA") Then Range("H" & Target.Row).ClearContents
End If
ElseIf Not Intersect(Target, Range("D21", "G21")) Is Nothing Then
' // If Area or Zone changes then recalc the Inst&Rental values //
Zone = [G21]: Location = [D21]
For i = 38 To 39
If (Range("A" & i) > 0) And (Len(Range("D" & i)) > 0) Then
Qty = Range("A" & i)
Desc = Range("D" & i)
If (Qty < 20000) Then
Range("H" & i) = Application.WorksheetFunction.Index(DataRng, Application.WorksheetFunction.Match(Desc, DescRng, 0), Application.WorksheetFunction.Match(Qty, QuanRng, 1) + ((Zone - 1) * 9))
End If
End If
Next i
ElseIf Not Intersect(Target, Range("G26:G35", "I26:I35")) Is Nothing Then
' // If any attempt is made to directly change the Inst+Rmvl or Rental rates //
ElseIf Not Intersect(Target, Range("B25:B34")) Is Nothing Then
' // Custom pricing in these cases. //
End If
Xit:
' Cleanup here. //
If Err.Number <> 0 Then
ErrMsg = "Error:" & str(Err.Number) & " was generated " _
& Err.Source & Chr(13) & Err.Description
MsgBox ErrMsg, , "Error", Err.HelpFile, Err.HelpContext
MsgBox "Processing Terminated."
Err.Clear
End If
For i = 25 To 27
If (Len(Range("A" & i)) = 0) Or (Len(Range("D" & i)) = 0) Then
Range("H" & i) = vbNullString
End If
Next i
' // Zap variables. //
Set DataRng = Nothing
Set DescRng = Nothing
Set HeadRng = Nothing
Application.Calculation = xlCalculationAutomatic
If Not Intersect(ActiveCell, [A26:I35]) Is Nothing Then
Application.EnableEvents = False
ActiveSheet.Unprotect ("as")
Range("K7").Formula = "=NOW()"
ActiveSheet.Protect ("as")
End If
ActiveSheet.Protect ("as")
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.CutCopyMode = False
End Sub