我想要一个执行以下操作的代码: 如果E列单元格中文本值的最后5个字符为“(UK)”,那么宏将复制由同一行中B,C,D,E列中的4个单元组成的范围,并将最后一个非下方粘贴工作表“Sheet 1”中的空行在同一列中(因此所有带“(UK)”的范围必须转移到工作表“Sheet1”);
答案 0 :(得分:0)
我只是发布我的代码。希望@Jonathan将学习它。
Sub CopyC()
Dim wb As Workbook
Dim ws As Worksheet
Dim sheet1lastrow As Long
Dim lastrow As Long
Set wb = ThisWorkbook
Set ws = wb.Worksheets("sheet1")
lastrow = ActiveSheet.Range("E" & Rows.Count).End(xlUp).Row
sheet1lastrow = ws.Range("E" & Rows.Count).End(xlUp).Row
For i = 1 To lastrow
If Right(ActiveSheet.Cells(i, 5).Value, 5) = "(UK)" Then
ActiveSheet.Range(Cells(i, 2), Cells(i, 5)).Copy
ws.Cells(sheet1lastrow + 1, 2).PasteSpecial xlValues
Application.CutCopyMode = False
Application.CutCopyMode = True
End If
Next
End Sub