我正在尝试合并以下2个代码。任何帮助将不胜感激
Private Sub Worksheet_Change(ByVal Target As Range)
Dim C As Range
If Intersect(Target, Me.Range("D:D")) Is Nothing Then Exit Sub
For Each C In Intersect(Target, Me.Range("D:D")).Cells
If C.Text = "y" Then
C.EntireRow.Copy Worksheets("Shipped").Cells(Rows.Count, "D").End(xlUp).Offset(1).EntireRow
C.EntireRow.Delete
End If
Next
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 8 Or Target.Cells.Count > 1 Then Exit Sub
Dim SortRange As Range
Set SortRange = Range(("A1"), Cells(Rows.Count, 8).End(xlUp))
SortRange.Sort Key1:=Range("H2"), Order1:=xlAscending, Header:=xlYes
End Sub
答案 0 :(得分:1)
Private Sub Worksheet_Change(ByVal Target As Range)
Dim C As Range, SortRange as Range
If Not Intersect(Target, Me.Range("D:D")) Is Nothing Then
For Each C In Intersect(Target, Me.Range("D:D")).Cells
If C.Text = "y" Then
C.EntireRow.Copy Worksheets("Shipped").Cells(Rows.Count, "D").End(xlUp).Offset(1).EntireRow
C.EntireRow.Delete
End If
Next
End If
'End Sub
'Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 8 And Target.Cells.Count <= 1 Then
Set SortRange = Range(("A1"), Cells(Rows.Count, 8).End(xlUp))
SortRange.Sort Key1:=Range("H2"), Order1:=xlAscending, Header:=xlYes
End If
End Sub
这些代码只会在原始Sub
的反面为真时运行,而不是If Statements
与If Statements
一起存在。我还评论了第一个Sub
的{{1}}声明声明和第一个Sub
的{{1}}声明。这是你想要的吗?