我需要以下VBA代码:
如果某列中的单元格包含某个单词,我需要将整行剪切并粘贴到不同的工作表上。我找到了一些代码,但它与目标表上的行匹配。我只是需要它来继续不同的工作表并从源中删除。
有人可以提出建议吗?
答案 0 :(得分:0)
如果您的"列"将标题作为其第一个单元格,然后您可以按照以下代码使用Sub main()
With Worksheets("mySheetName") '<--| reference the worksheet with data (change "mySheetName" to your actual worksheet with data name
With .Range("A1", .Cells(.Rows.count, "A").End(xlUp)) '<--| reference its "column" (change "A" occurrences to your actual column with data index)
.AutoFilter Field:=1, Criteria1:="d" '<--| change "word" to your actual word to be looked for
If Application.WorksheetFunction.Subtotal(103, .Cells) > 1 Then
With .Resize(.Rows.count - 1).Offset(1).SpecialCells(xlCellTypeVisible)
.Copy Worksheets("myOtherSheetName").Range("A1")
Application.DisplayAlerts = False
.SpecialCells(xlCellTypeVisible).Delete
Application.DisplayAlerts = True
End With
End If
.AutoFilterMode = False
End With
End With
End Sub
(请参阅注释以根据您的实际需要进行调整)
public static void reduceBooks(Book[] reduceAra) {
for (int i = 0; i < reduceAra.length; i++) {
Book bookReduce = reduceAra[i];
double price = bookReduce.getPrice();
double reducedPrice = price * .60;
bookReduce.setPrice(reducedPrice);
}
}