[英]Automatically Copy Cells to Another Worksheet Based on Specific Words
When the word "Overdue" appears in a cell (in column H), I want the name (in column A) and the date (in column F) in that row to automatically copy and paste into another worksheet (named HomePage) and appear in column C12 and E12. 当单词“过期”出现在单元格中(在H列中)时,我希望该行中的名称(在A列中)和日期(在F列中)自动复制并粘贴到另一个工作表(名为HomePage)中并显示在列C12和E12中。
I have the following code, but it's cutting and pasting the entire row. 我有以下代码,但它剪切并粘贴了整行。 I just want a copy and paste of the name and date to my HomePage.
我只想将名称和日期复制粘贴到我的主页上。
Private Sub Worksheet_Change (ByVal Target As Range)
If Target.Column = 8 Then
If Target.Value = "Overdue" Then
R = Target.Row
Rows(R).Cut
Worksheets("HomePage").Select
With ActiveSheet
lastrow = .Cells(.Rows.Count, "C").End(xlUp).Row + 1
.Cells(lastrow, 1).Select
.Paste
End With
End If
End If
End Sub
Since you only want two cells, why copy and paste? 由于只需要两个单元格,为什么要复制和粘贴? Just assign the values directly.
只需直接分配值即可。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim R As Long
If Target.Column = 8 Then
If Target.Value = "Overdue" Then
With Sheets("Homepage")
R = .Cells(.Rows.Count, 3).End(xlUp).Row + 1
.Cells(R, 3) = Target.Offset(0, -7) ' Column C = Column A
.Cells(R, 5) = Target.Offset(0, -2) ' Column E = Column F
End With
End If
End If
End Sub
as per your narrative 根据您的叙述
I want the name (in column A) and the date (in column F) in that row to automatically copy and paste into another worksheet (named HomePage) and appear in column C12 and E12.
我希望该行中的名称(在A列中)和日期(在F列中)自动复制并粘贴到另一个工作表(名为HomePage)中,并显示在C12和E12列中。
place the following code in your worksheet code pane 将以下代码放在工作表代码窗格中
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Column = 8 And .Value = "Overdue" Then
Sheets("Homepage").Range("C12").Value = Range(.row, "A")
Sheets("Homepage").Range("E12").Value = Range(.row, "F")
End If
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.