简体   繁体   English

根据特定的单词自动将单元格复制到另一个工作表

[英]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.

相关问题 根据条件将单元格从特定列复制到另一个工作表 - Copy cells from a specific column to another worksheet based on criteria VBA代码可将特定单元格中的特定单词复制并粘贴到另一个工作表中 - VBA code to copy and paste specifc words in different cells to another worksheet 根据列中的日期将行中的特定单元格复制到月工作表 - Copy specific cells in a row to month worksheet based on date in column 将特定单元格从一个工作表复制并粘贴到另一个工作表 - Copy and Paste Specific Cells from one worksheet to another 如果发现文本,则在另一工作表中复制同一行的特定单元格 - Copy specific cells of same row in another worksheet if text found 如何将具有特定值的单元格中的数据复制到另一个工作表? - How to copy data from cells with specific value to another worksheet? 根据单元格值将行复制并粘贴到另一个工作表 - Copy and Paste Rows to another worksheet based on a cells value 根据工作表名称将单元格复制到其他工作表 - copy cells to different worksheet based on worksheet name 将特定的单元格复制到另一个工作表 - Copying specific cells to another worksheet 需要一个宏以根据单元格中的数据将一个工作表中的行中的特定单元格复制到另一工作表中的特定单元格 - Need a macro to copy specific cells from a row in one worksheet to a specific cells in another worksheet base upon a data in the cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM