I trying to make a project to my work but I stuck now with Vb for like a week every time I fix a problem I faced a new one until now I face a problem I can't solve it I will attach the file and the problem when I try to add a new row or delete a row it's case error
link to my file :
my code in worksheet section
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("E:E")) Is Nothing Then
ElseIf Range("E" & Target.Row) <> "" Then
Range("G" & Target.Row) = "In Progress"
Else
Range("g" & Target.Row) = ""
End If
If Not Application.Intersect(Range("H:H"), Range(Target.Address)) _
Is Nothing Then
Dim myToAdd As String
If Target.Column = 8 Then
If Target.Value = "" Then Exit Sub
If Target.Value = "Test1" Then
myToAdd = "Test1@test1.com"
ElseIf Target.Value = "test2" Then
myToAdd = "Test2@test2.com"
'Else
'etc.....
End If
If MsgBox("Do you want to send EMAIL to " & Target & " ?", vbYesNo + vbQuestion, "Confirm Sending Email") = vbNo Then Exit Sub
End If
With CreateObject("Outlook.Application").CreateItem(0) '0 will create a new email item
.To = myToAdd
.CC = ""
.Subject = "You Have a new ( Activities / Tasks / Items )" & " " & Target.Offset(0, -3).Value & " " & "assigned to you"
.Body = "Dear," & " " & Target & vbNewLine & vbNewLine & "You Have a new ( Activities / Tasks / Items )" & " " & Target.Offset(0, -3).Value & " " & "assigned to you Please follow up till have it Closed or assigned to the responsible ." & vbNewLine & vbNewLine & vbNewLine & vbNewLine & "Keep it up" & vbNewLine & "STANDARDIZATION & COMPLIANCE"
.display 'Change this to .Send
End With
End If
End Sub
code in work book section
Private Sub Workbook_Open()
ActiveWindow.Zoom = 100
End Sub
code in module
Option Explicit
Private Sub CommandButton1_Click()
addNewRow
End Sub
Sub addNewRow()
' Do not insert a row before the first row.
Dim iTopRow As Integer
iTopRow = 5
If (ActiveCell.Row > iTopRow) Then
' Get the active row number.
Dim rowNum As Integer
rowNum = ActiveCell.Row
Rows(rowNum).EntireRow.Insert ' Insert a new row.
' Change the Codes (in first column).
Cells(ActiveCell.Row, 1) = rowNum - 4 ' For the active cells.
Dim iTotalRows As Integer ' Get the total used range rows.
iTotalRows = ActiveSheet.UsedRange.Rows.Count
Dim iRows As Integer
For iRows = rowNum + 1 To iTotalRows
Cells(iRows, 1) = iRows - 4
Cells(Application.ActiveCell.Row, 7).Select
Next iRows
End If
End Sub
any help will be more than appropriation
link to my file :
my code in worksheet section
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("E:E")) Is Nothing Then
ElseIf Range("E" & Target.Row) <> "" Then
Range("G" & Target.Row) = "In Progress"
Else
Range("g" & Target.Row) = ""
End If
If Not Application.Intersect(Range("H:H"), Range(Target.Address)) _
Is Nothing Then
Dim myToAdd As String
If Target.Column = 8 Then
If Target.Value = "" Then Exit Sub
If Target.Value = "Test1" Then
myToAdd = "Test1@test1.com"
ElseIf Target.Value = "test2" Then
myToAdd = "Test2@test2.com"
'Else
'etc.....
End If
If MsgBox("Do you want to send EMAIL to " & Target & " ?", vbYesNo + vbQuestion, "Confirm Sending Email") = vbNo Then Exit Sub
End If
With CreateObject("Outlook.Application").CreateItem(0) '0 will create a new email item
.To = myToAdd
.CC = ""
.Subject = "You Have a new ( Activities / Tasks / Items )" & " " & Target.Offset(0, -3).Value & " " & "assigned to you"
.Body = "Dear," & " " & Target & vbNewLine & vbNewLine & "You Have a new ( Activities / Tasks / Items )" & " " & Target.Offset(0, -3).Value & " " & "assigned to you Please follow up till have it Closed or assigned to the responsible ." & vbNewLine & vbNewLine & vbNewLine & vbNewLine & "Keep it up" & vbNewLine & "STANDARDIZATION & COMPLIANCE"
.display 'Change this to .Send
End With
End If
End Sub
code in work book section
Private Sub Workbook_Open()
ActiveWindow.Zoom = 100
End Sub
code in module
Option Explicit
Private Sub CommandButton1_Click()
addNewRow
End Sub
Sub addNewRow()
' Do not insert a row before the first row.
Dim iTopRow As Integer
iTopRow = 5
If (ActiveCell.Row > iTopRow) Then
' Get the active row number.
Dim rowNum As Integer
rowNum = ActiveCell.Row
Rows(rowNum).EntireRow.Insert ' Insert a new row.
' Change the Codes (in first column).
Cells(ActiveCell.Row, 1) = rowNum - 4 ' For the active cells.
Dim iTotalRows As Integer ' Get the total used range rows.
iTotalRows = ActiveSheet.UsedRange.Rows.Count
Dim iRows As Integer
For iRows = rowNum + 1 To iTotalRows
Cells(iRows, 1) = iRows - 4
Cells(Application.ActiveCell.Row, 7).Select
Next iRows
End If
End Sub
any help will be more than appropriation
Last edited by a moderator: