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:

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

mohadin

Well-known Member
Joined
Mar 22, 2015
Messages
1,088
Office Version
  1. 2013
Platform
  1. Windows
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
 

New Student 2020

New Member
Joined
Sep 1, 2020
Messages
9
Office Version
  1. 365
Platform
  1. Windows
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
 

mohadin

Well-known Member
Joined
Mar 22, 2015
Messages
1,088
Office Version
  1. 2013
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,126,998
Messages
5,622,097
Members
415,876
Latest member
csibonga2k17

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
Top