joelmidiowa
New Member
- Joined
- Dec 16, 2020
- Messages
- 6
- Office Version
- 365
- Platform
- Windows
i am trying to add the two different lines of code to the same excel sheet. one to automatically add rows then the next i want it to auto sort column G. i when i add both to the same sheet it won't work
Private Sub Worksheet_Change(ByVal Target As Range)
'Test if change is in column B and only one cell changed
If Not Intersect(Target, Me.Columns("B")) Is Nothing And _
Target.Cells.Count = 1 Then
Target.Offset(1, 0).EntireRow.Insert Shift:=xlDown 'Insert row below data entry
'Target.EntireRow.Insert Shift:=xlDown 'Insert row above data entry
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Not Intersect(Target, Range("G:G")) Is Nothing Then
Range("G1").Sort Key1:=Range("G2"), _
Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
'Test if change is in column B and only one cell changed
If Not Intersect(Target, Me.Columns("B")) Is Nothing And _
Target.Cells.Count = 1 Then
Target.Offset(1, 0).EntireRow.Insert Shift:=xlDown 'Insert row below data entry
'Target.EntireRow.Insert Shift:=xlDown 'Insert row above data entry
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Not Intersect(Target, Range("G:G")) Is Nothing Then
Range("G1").Sort Key1:=Range("G2"), _
Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
End If
End Sub