我对VBA非常陌生,我需要一些帮助。
所示我想将其中包含“图层名称”的行和接下来的两行(几何图形和要素计数)复制到下一张图纸。我尝试了这里提到的代码if cell contains specific text, copy whole row + next row当然,将所有'1'改为'2'。但它没有用。任何形式的帮助将不胜感激
答案 0 :(得分:1)
试试这个:
Sub layer()
j = 1
For i = 1 To 100
If Left(Cells(i, 1), 10) = "Layer name" Then
For k = 0 To 2
Sheets(2).Cells(j + k, 1) = Cells(i + k, 1)
Next k
j = j + 3
End If
Next i
End Sub
答案 1 :(得分:0)
试试这个:
Sub Test()
For Each Cell In Sheets(1).Range("A:A")
If Left(Cell.Value, 11) = "Layer name:" Then
matchRow = Cell.Row
Rows(matchRow & ":" & matchRow + 2).Select
Selection.Copy
Sheets(2).Select
lastRow = ActiveSheet.UsedRange.Rows.Count
If lastRow > 1 Then lastRow = lastRow + 2
ActiveSheet.Range("A" & lastRow).Select
ActiveSheet.Paste
Sheets(1).Select
End If
Next
End Sub