简体   繁体   English

Excel 2010:VBA删除标题包含多个表/工作表中的文本的列

[英]Excel 2010: VBA to delete columns with headers containing text across multiple tables/worksheets

I have macros to dynamically create columns (via an "Add" button) in tables across multiple sheets in my workbook, in some cases on sheets containing multiple tables. 我有宏可以在工作簿中跨多个工作表的表中动态创建列(通过“添加”按钮),有时在包含多个表的工作表中也可以。 I would like to also have a "Remove" button that finds all columns containing text "toolname" in all tables in the workbook and deletes them. 我还希望有一个“删除”按钮,用于在工作簿的所有表中查找包含文本“工具名”的所有列,并将其删除。

I've tried a few different loops but am not sure how to go about actually finding and deleting columns based on said text, whether it should be a structured reference or a range, etc. Pretty big vba noob here so any help in the right direction would definitely be appreciated! 我尝试了几个不同的循环,但是不确定如何根据所说的文本实际查找和删除列,无论是结构化引用还是范围等。在这里,vba noob相当大,因此任何帮助都对方向肯定会感激!

Something like this to find what you are looking for ? 这样的东西可以找到您想要的?

Dim rng As Range

Set rng = Cells.Find(What:="toolname", After:=ActiveCell, LookIn:=xlFormulas, _
                LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
                False, SearchFormat:=False)

If Not rng Is Nothing Then
   'if no matches is found
End If

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

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