two vba codes for the same worksheet

New Student 2020

New Member
Joined
Sep 1, 2020
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hello there

I was wondering if it is possible to add a second macro/rule to the same worksheet?

this one below is already on a worksheet:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 7 Then Exit Sub
If Target.Cells.Count > 7 Then Exit Sub
With Target.Offset(0, -6)
.Value = Now
.NumberFormat = "DD/MM/YYYY"
End With
End Sub

I would also like to add another one to the same worksheet so that when the value of a certain cell/range is between a range for example 5 and below, a pop up message box will alert of the low stock number and also show the name of the stock item contained in another cell.

is that possible?

Thank you very much
Franco
 
Last edited by a moderator:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
SEE IF THIS EXAMPLE HELPS
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column <> 7 And Target.Address <> "$B$2" Then Exit Sub
    If Target.Cells.Count > 7 And Target.Cells.Count <> 1 Then Exit Sub
    With Target
        If Target.Column = 7 Then
            .Offset(0, -6).Value = Now
            .NumberFormat = "DD/MM/YYYY"
        Else
            Target.Offset(1) = 0
        End If
    End With
 
Upvote 0
Hi
thank you for your help but did not work....
I would also like to add another code to the same worksheet so that when the value of a certain cell/range is between a range for example 5 and below, a pop up message box will alert of the low stock number and also show the name of the stock item contained in another cell.

is that possible?

Thank you very much
 
Upvote 0
I don't know what is the certain cell so let's say Range("H2") and the stock name in next column of the certain cell then <<Range("I2")>>
Try
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column <> 7 And Target <> Range("$H$2") Then Exit Sub '<< Change  to certain cell/range  <<
    If Target.Cells.Count > 7 And Target.Cells.Count <> 1 Then Exit Sub
    With Target
        If Target.Column = 7 Then
            .Offset(0, -6).Value = Now
            .NumberFormat = "DD/MM/YYYY"
        Else
            If Target < 5 Then MsgBox " low stock number " & Target.Offset(, 1).Value ' name of the stock item contained in range($I$2)
            Target.Select
        End If
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top