查找文本,插入行,然后更改特定的文本后复制和粘贴

我有一个行和列的数据,我希望我的macros在一列中find某些文本(位置),并find该位置创build2行或更多行并复制find的位置行的数据,但更改位置的增量为1.例如,如果它在“位置列伦敦”中find值,则将整行复制到2个新插入的行中,但将伦敦文本更改为伦敦1和伦敦2,依此类推。 请帮忙。

sub Insert_CopyPaste() Dim LastRow As Long With Sheets("Sheet2") .Activate LastRow = .Range("C6000").End(xlUp).Row For i = 2 To LastRow If (InStr(1, .Range("c" & i).Value, "03M-EX", vbTextCompare) > 0) Then .Range("a" & i).EntireRow.Copy .Range("a" & i + 1).EntireRow.Insert .Range("a" & i + 1).PasteSpecial xlPasteValues End If Next End With Exit Sub End Sub 

我确定这是你以后的事情。 如果不清楚,我可以解释。

 sub Insert_CopyPaste() Dim LastRow As Long, i as long, txt as string txt = "03M-EX" 'set text to search With Sheets("Sheet2") LastRow = .Range("C6000").End(xlUp).Row while i <= lastrow If .Range("c" & i).Value = txt Then .Range("a" & i).EntireRow.Copy .Range("a" & i + 1).EntireRow.Insert .Range("a" & i + 1).PasteSpecial xlPasteValues .Range("c" & i + 1).value = txt & "1" 'add 1 to text i = i + 1 'skip newly added row lastrow = lastrow + 2 'increase last row reference by 2 .Range("a" & i).EntireRow.Copy .Range("a" & i + 1).EntireRow.Insert .Range("a" & i + 1).PasteSpecial xlPasteValuesxlPasteValues .Range("c" & i + 1).value = txt & "2" End If i = i + 1 'goto next row to check loop End With End Sub