我有一个代码可以单击按钮删除行。但它仅适用于放置按钮的工作表。 (它可以删除包含文本“删除”的单元格)。如何修改代码,使得如果按钮位于 Sheet 1 中,删除行按钮也可以删除 Sheet 1、Sheet 2 和 Sheet 3 中的同一行?
这是我当前的代码。
Sub RectangleRoundedCorners10_Click()
Dim rng As Range
Set rng = Range("a9:zz2000")
Do
Set A = rng.Find("Delete*", LookIn:=xlValues)
If Not A Is Nothing Then A.EntireRow.Delete
Loop While Not A Is Nothing
End Sub
Next ws
End Sub
您似乎想要修改代码,以便单击工作表 1 上的按钮将删除工作表 1、2 和 3 中包含文本“删除”的行。
这是修改后的代码:
Sub RectangleRoundedCorners10_Click()
Dim ws As Worksheet
Dim rng As Range
Dim A As Range
' Loop through the sheets you want to modify
For Each ws In ThisWorkbook.Sheets(Array("Sheet1", "Sheet2", "Sheet3")) ' Replace with your sheet names
Set rng = ws.Range("a9:zz2000")
Do
Set A = rng.Find("Delete*", LookIn:=xlValues)
If Not A Is Nothing Then A.EntireRow.Delete
Loop While Not A Is Nothing
Next ws
End Sub
此代码将循环遍历指定的工作表(Sheet1、Sheet2 和 Sheet3),并删除指定范围内包含文本“Delete”的行。
确保将
"Sheet1", "Sheet2", "Sheet3"
替换为您要修改的工作表的实际名称。