Excel VBA检查单元格中的特定值 [英] Excel VBA Check for specific value in cell

查看:82
本文介绍了Excel VBA检查单元格中的特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在的处境很麻烦.我的问题是,如果它的单元格值包含字符串 Total Attachment Size:,有什么方法可以删除该单元格的内容?

I'm having a big trouble with my situation right now. My question is, is there any way I can delete the cell contents if its cell value has a string Total Attachment Size: ?

我有这部分,但不知道如何进行.一直在网上寻找任何想法,但不幸的是,这还不够.

I have this part but don't know how to proceed. Been searching in the net for any ideas, but unfortunately it is not enough.

dim lastrow as integer
dim ws as worksheet

set ws = ThisWorkbook.sheets("Sheet1")

lastrow = ws.cells(rows.count, 8).end(xlup).row

if ws.range("H" & lastrow) contains `Total Attachment Size: ` then 
    ws.range("H" & lastrow).clearcontents
    lastrow = ws.cells(rows.count, 8).end(xlup).row

end if

非常感谢您的帮助.

推荐答案

这与您的代码相同,如果您要检查所有H列值,请告诉我,我们可以运行循环并清除包含该值的所有单元格

This is as per your code, if you want to check all H column values then let me know, we can run a loop and clear all cells containing the value

Dim str As String
On Error Resume Next
str = Application.WorksheetFunction.Search("Total Attachment Size: ",Sheet1.Range("H" & Sheet1.Range("H500000").End(xlUp).Row).Value, 1)

If Err.Number = 0 Then

Sheet1.Range("H" & Sheet1.Range("H500000").End(xlUp).Row).ClearContents

End If

这篇关于Excel VBA检查单元格中的特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆