简体   繁体   English

excel VBA匹配不同工作表上的2个单元格,如果匹配则删除工作表

[英]excel VBA match 2 cell on different sheets if match then delete sheet

I have sheet with name LIST, and in cell K15 is some value.我有名称为 LIST 的工作表,在单元格 K15 中是一些值。 What i need is for macro to check all other sheets and if it match value from (LIST) - (K15) to cell (B4) on all other sheets in workbook, and it will be always that place (B4).我需要的是宏来检查所有其他工作表,以及它是否与工作簿中所有其他工作表上的 (LIST) - (K15) 到单元格 (B4) 的值匹配,并且它将始终是那个地方 (B4)。 If it get match then delete that sheet.如果匹配,则删除该工作表。

So it is some kind of match loop macro.所以它是某种匹配循环宏。

Please help me请帮我

Sub DeleteSheets01()

 Dim ws As Worksheet
 For Each ws In ActiveWorkbook.Worksheets
   If Worksheets("LIST").Range("K15") = LenB(ActiveSheet.Range("B4")) Then ActiveSheet.Delete
 Next ws
 End Sub

I have done it我已经做了

Sub DeleteSheets01()

Application.DisplayAlerts = False
Dim ws As Worksheet
  For Each ws In ActiveWorkbook.Worksheets
   If ws.Range("B4") = Worksheets("LIST").Range("K15") Then
       ws.Delete
   End If
  Next ws
 Application.DisplayAlerts = True
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM