Excel How to run multiple Private Sub Worksheet_Change(ByVal Target As Range)

Dec 2, 2017
Reaction score
hai there, im new user excel vba, i want to use this to code for my project but getting error.Please help me.below is my code what i;m done..its for auto date and auto numbers...sory my english not very good..

'auto date
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False

Dim sheet1 As Workbooks
For sheet = 13 To 1000
If Cells(sheet, "C").Value <> "" And Cells(sheet, "B") = "" Then
Cells(sheet, "B").Value = Date
Cells(sheet, "B").NumberFormat = "dd / mm / yyyy"
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
Dim maxNumber
If Not Intersect(Target, Range("B:B")) Is Nothing Then
' don't run when more than one row is changed
If Target.Rows.Count > 1 Then Exit Sub
' if column A in the current row has a value, don't run
If Cells(Target.Row, 1) > 0 Then Exit Sub
' get the highest number in column A, then add 1 and write to the
' current row, column A
maxNumber = Application.WorksheetFunction.Max(Range("A:A"))
Target.Offset(0, -1) = maxNumber + 1
End If
End Sub


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question