移动一行到工作表的工作表名称的进入在Excel中使用VBA一行之后
问题:
在D列中输入工作表名称时,条目的行将移至相应的工作表
答案:
在“此工作簿”模块中插入以下代码。
Private Sub Worksheet_Change(ByVal Target As Range) Dim wks As Worksheet Dim intRow As Integer If Target.Column <> 4 Then Exit Sub If IsEmpty(Target) Then Exit Sub On Error Resume Next Set wks = Worksheets(Target.Value) If Err > 0 Or wks Is Nothing Then MsgBox "Sheet name Not Found!" Exit Sub End If On Error GoTo 0 With wks intRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1 .Range(.Cells(intRow, 1), .Cells(intRow, 3)).Value = _ Range(Cells(Target.Row, 1), Cells(Target.Row, 3)).Value End With Rows(Target.Row).Delete End Sub