Hi All, I have this code in here which looks for print cartridges quantities in columns and if is below certain level (takes from worksheet "Info") it populates email (calls command to create) to order more, records who and when did it and informs to check before ordering more. Thing is it works fine if I have only 2 printers but as soon as I add another one code either stops working and nothing is happening or it creates email even if stock levels are above. So I`m wondering can someone help me out with this?
Thanks in advance for the help
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim FindString As Date
Dim Rng As Range
Dim ModBy As String
Dim DateBy As Date
Dim Orderdays As Long
Dim Cell1 As Range
Dim Cell2 As Range
'Dim CellAddress1 As String
'Set Cell1 = ThisWorkbook.Worksheets(9).Cells(5, 2)
'CellAddress1 = Cell1.Parent.Name & "!" & Cell1.Address(External:=False)
'Dim Cell2 As Range
'Dim CellAddress2 As String
'Set Cell2 = ThisWorkbook.Worksheets(9).Cells(5, 3)
'CellAddress2 = Cell2.Parent.Name & "!" & Cell2.Address(External:=False)
If Application.WorksheetFunction.IsNumber(Target.Cells) Then
If Not Intersect(Range("C:C"), Target.Cells) Is Nothing Then
ModBy = Sheet9.Range("C11").Value
DateBy = Sheet9.Range("B11").Value
Orderdays = DateDiff("D", DateBy, Date)
'Dim CellAddress1 As String
Set Cell1 = ThisWorkbook.Worksheets("OrderDetail").Cells(11, 2)
CellAddress1 = Cell1.Parent.Name & "!" & Cell1.Address(External:=False)
'Dim CellAddress2 As String
Set Cell2 = ThisWorkbook.Worksheets("OrderDetail").Cells(11, 3)
CellAddress2 = Cell2.Parent.Name & "!" & Cell2.Address(External:=False)
FindString = dhLastDayInWeek
Sheet8.Activate
Range("A:A").Select
With Range("A:A")
Set Rng = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
Application.Goto Rng, True
Else
MsgBox "Nothing found"
End If
End With
Rng.Select
ActiveCell.Offset(0, 2).Select
If ActiveCell.Value <= Sheets("Info").Range("B2") Then
If Orderdays >= 8 Then
If MsgBox("Would you like to send an Email to Order more…?", vbQuestion + vbYesNo) = vbNo Then
Exit Sub
End If
Call Mail_HP_toner_81X
'Email(, Sheets("Info").Range("C4") & " Bottles of Markem 5005 Black Ink", "Please Order Some More Markem 5005 Black Ink", CellAddress1, CellAddress2)
'Sheet9.Range("B5").Value = Date
'Sheet9.Range("C5").Value = fOSUserName
Else
msg = MsgBox("An Order was placed by " & ModBy & " on the " & DateBy & vbCrLf & vbCrLf & "Please Check with Laura before Ordering", vbInformation, "Please Check Before Ordering")
Sheet9.Range("D11").Value = Date
Sheet9.Range("E11").Value = fOSUserName
End If
End If
Else
If Not Intersect(Range("L:L"), Target.Cells) Is Nothing Then
ModBy = Sheet9.Range("C12").Value
DateBy = Sheet9.Range("B12").Value
Orderdays = DateDiff("D", DateBy, Date)
FindString = dhLastDayInWeek
'Dim CellAddress1 As String
Set Cell1 = ThisWorkbook.Worksheets("OrderDetail").Cells(12, 2)
CellAddress1 = Cell1.Parent.Name & "!" & Cell1.Address(External:=False)
'Dim CellAddress2 As String
Set Cell2 = ThisWorkbook.Worksheets("OrderDetail").Cells(12, 3)
CellAddress2 = Cell2.Parent.Name & "!" & Cell2.Address(External:=False)
Sheet8.Activate
Range("A:A").Select
With Range("A:A")
Set Rng = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
Application.Goto Rng, True
Else
MsgBox "Nothing found"
End If
End With
Rng.Select
ActiveCell.Offset(0, 5).Select
If ActiveCell.Value <= Sheets("Info").Range("B3") Then
If Orderdays >= 8 Then
If MsgBox("Would you like to send an Email to Order more…?", vbQuestion + vbYesNo) = vbNo Then
Exit Sub
End If
'If Orderdays >= 0 Then
Call Mail_PR21_22
'Email(, Sheets("Info").Range("C5") & " Boxes of Markem Cleaning Wipes." & Chr(13) & "An Order was last placed by " & ModBy & " on the " & DateBy, "Please Order Some More Markem Cleaning Wipes", CellAddress1, CellAddress2)
'Sheet9.Range("B4").Value = Date
'Sheet9.Range("C4").Value = fOSUserName
Else
msg = MsgBox("An Order was placed by " & ModBy & " on the " & DateBy & vbCrLf & vbCrLf & "Please Check with Laura before Ordering", vbInformation, "Please Check Before Ordering")
Sheet9.Range("D12").Value = Date
Sheet9.Range("E12").Value = fOSUserName
End If
End If
Else
If Not Intersect(Range("O:O"), Target.Cells) Is Nothing Then
ModBy = Sheet9.Range("C6").Value
DateBy = Sheet9.Range("B6").Value
Orderdays = DateDiff("D", DateBy, Date)
FindString = dhLastDayInWeek
'Dim CellAddress1 As String
Set Cell1 = ThisWorkbook.Worksheets("OrderDetail").Cells(6, 2)
CellAddress1 = Cell1.Parent.Name & "!" & Cell1.Address(External:=False)
'Dim CellAddress2 As String
Set Cell2 = ThisWorkbook.Worksheets("OrderDetail").Cells(6, 3)
CellAddress2 = Cell2.Parent.Name & "!" & Cell2.Address(External:=False)
Sheet8.Activate
Range("A:A").Select
With Range("A:A")
Set Rng = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
Application.Goto Rng, True
Else
MsgBox "Nothing found"
End If
End With
Rng.Select
ActiveCell.Offset(0, 5).Select
If ActiveCell.Value <= 1 Then ' Sheets("Info").Range("B6") Then
If Orderdays >= 8 Then
If MsgBox("Would you like to send an Email to Order more…?", vbQuestion + vbYesNo) = vbNo Then
Exit Sub
End If
'If Orderdays >= 0 Then
Call Mail_Lex_Rb
'Email(, Sheets("Info").Range("C6") & " LEXMARK 11A3540 Ribbons", "Please Order Some More LEXMARK Ribbons for NR01", CellAddress1, CellAddress2)
'Mail_PR21_22
'Email(, Sheets("Info").Range("C5") & " Boxes of Markem Cleaning Wipes." & Chr(13) & "An Order was last placed by " & ModBy & " on the " & DateBy, "Please Order Some More Markem Cleaning Wipes", CellAddress1, CellAddress2)
'Sheet9.Range("B4").Value = Date
'Sheet9.Range("C4").Value = fOSUserName
Else
msg = MsgBox("An Order was placed by " & ModBy & " on the " & DateBy & vbCrLf & vbCrLf & "Please Check with Laura before Ordering", vbInformation, "Please Check Before Ordering")
Sheet9.Range("D6").Value = Date
Sheet9.Range("E6").Value = fOSUserName
End If
End If
''''''''''''''''''''''''''''''''''''''''''''
Else 'add one "exit sub" and "end if" for every new entry/printer
Exit Sub
End If
Exit Sub
End If
Exit Sub
End If
Else
Exit Sub
End If
Set Rng = Nothing
Set Cell1 = Nothing
Set Cell2 = Nothing
End Sub
Thanks in advance for the help