vba 创建宏以删除符合特定条件的列中的单元格内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16067725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
create a macro to delete cell content in a column that meets certain criteria
提问by A h
Hello can someone help me. I have three columns and I want to search each column and delete content if it meets certain criteria.
你好有人可以帮助我。我有三列,我想搜索每一列并删除满足特定条件的内容。
Column B delete only cells with names
Columns C delete only cells with the word tray and a number
Column F delete only cells with * followed by four 0000 then ends with *
This is what I came up with but it isn't working and I am not sure what to do. I have searched and searched. How do I do this thanks?
B 列仅删除带有名称的单元格
C 列仅删除带有文字托盘和数字的单元格 F 列仅删除带有 * 后跟四个 0000 然后以 * 结尾的单元格 这是我想出的,但它不起作用,我是不知道该怎么办。我已经搜索和搜索。我该怎么做谢谢?
column B name column cell format FN,LN Clear any names from row 16 to lastrow. Some 'row may have dates and time I don't want to touch those
B 列名称列单元格格式 FN,LN 清除从第 16 行到最后一行的所有名称。有些'行可能有日期和时间我不想碰那些
column C range format Tray 226985 clear the content of any rows in that column with the word tray followed by a number to the lastrow
列 C 范围格式 Tray 226985 清除该列中任何行的内容,字盘后跟一个数字到最后一行
column F range format 000000226985begins with a * then four 0000 and ends with a * delete cell content with that format to the lastrow
列 F 范围格式000000226985以 * 开头,然后是四个 0000 并以 * 结尾删除具有该格式的单元格内容到最后一行
Sub Macro1()
Range(b1, b65536).Value = ("*,*").clearcontent
Range(c1, c65536).Value = tray(*).clearcontent
Range(f1, f65536).Value = ("*0000*").clearcontent
End Sub
回答by Simon1979
the below should complete your required task by looping through each cell in column A and checking the offset cells. I have replicated your criteria but I am not familiar with 'tray(*)', I think you may want to replace that line with something like:
下面应该通过循环遍历 A 列中的每个单元格并检查偏移单元格来完成您所需的任务。我已经复制了您的标准,但我不熟悉“托盘(*)”,我认为您可能想用以下内容替换该行:
If c.Offset(0, 2).Value Like "Tray*" Then
You may need to look into alternatives if it HAS to be a number after 'Tray', I'll leave it to you to get the criteria right but hopefully I have helped with the method of looping.
如果它必须是“托盘”之后的数字,您可能需要研究替代方案,我将把它留给您来获得正确的标准,但希望我对循环方法有所帮助。
Dim sh As Worksheet
Dim rng As Range, c As Range
Set sh = ActiveSheet
Set rng = sh.Range("A:A")
For Each c In rng
If c.Offset(0, 1).Value Like "*,*" Then
c.Offset(0, 1).ClearContents
End If
If c.Offset(0, 2).Value Like tray(*) Then ' see note on replacing this line
c.Offset(0, 2).ClearContents
End If
If c.Offset(0, 5).Value Like "*0000*" Then
c.Offset(0, 5).ClearContents
End If
Next c