简体   繁体   English

如何根据单元格值清除行中的内容?

[英]How do I clear content in rows based on cell value?

I copy a lot of information (1000 rows and at least 24 columns) from one sheet to another. 我将很多信息(1000行和至少24列)从一张纸复制到另一张纸。 A lot of the cells contains "". 许多单元格包含“”。 This makes my other formulas(for example: A1-B1) to show an value error if either of these cells contains "". 如果这些单元格中的任何一个包含“”,这会使我的其他公式(例如:A1-B1)显示值错误。 I believe I can solve the problem by never pasting "" but a "0" instead. 我相信我可以通过不粘贴“”而是粘贴“ 0”来解决问题。 But I would like to delete these "0" afterwards. 但是,我想随后删除这些“ 0”。

There could be values in the first 3 rows but the other 997 rows have "". 前3行中可能有值,但其他997行中有“”。

I would think I need to tell my macro to (Cell A1 in the "sheet1" sheet displays "G5:H12". the cells I need to delete): 我想我需要告诉宏(“ sheet1”工作表中的单元格A1显示“ G5:H12”。我需要删除的单元格):

Rowstodelete = Sheets("sheet1").Range("A1").Value

Sheets("sheet1").Range("rowstodelete").clearcontent

This does not work. 这是行不通的。 anyone know how to do this? 有人知道怎么做吗?

Summary(new example) 摘要(新示例)

If cell A1 = "B1:B2" I want to clear the content of B1 and B2, but if A1 now = B4:B6, that is the cells that should be cleared. 如果单元格A1 =“ B1:B2”,我想清除B1和B2的内容,但是如果现在A1 = B4:B6,则应清除这些单元格。

Try this one: 试试这个:

With Worksheets(1).Range( _'PLACE YOUR RANGE
                                            ) 
    Set c = .Find(0, lookin:=xlValues) 
    If Not c Is Nothing Then 
        firstAddress = c.Address 
        Do 
           c.Value = "" 
            Set c = .FindNext(c) 
        Loop While Not c Is Nothing
    End If 
End With

Hope it helps 希望能帮助到你

Anyhow, I think that will be simpler to place a condition in your operation formula: =IF(OR(A1="",B1=""),Make when there is an unexpected value,A1-B1) 无论如何,我认为在您的运算公式中放置条件会更简单: =IF(OR(A1="",B1=""),Make when there is an unexpected value,A1-B1)

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

相关问题 如何根据单元格值创建新行? - How do I create new rows based on cell value? 如何根据单元格值在表格中创建行并根据 Excel 中的单元格值填充列 - How do I create rows in a table based off a cell value and fill a column also based off the cell values in Excel Excel / VBA-根据位置将多行合并为一-如何检查单元格值,然后将值保存在另一个单元格中? - Excel / VBA - Multiple Rows to One Based on Positioning - How do i check cell value then save the value in another cell? 根据特定值清除表格中整列的单元格内容 - Clear cell content for the entire column in table, based on a specific value 根据特定单元格值清除 Excel 表中的列内容 - Clear column content in Excel table based on specific cell value 如何根据另一个单元格将单元格值限制为最大值? - How do I restrict a cell value to a maximum based on another cell? 根据其他单元格计算清除单元格内容 - Clear cell content based on another cell calculation Excel:如何根据值更改单元格内容 - Excel: How do I change the Cell Content based on the Values 如何根据单元格内容选择多个工作表进行移动? - How do I select multiple worksheets to move based on cell content? 根据相同的内容值从随机行中获取单元格值 - Get cell value from random rows based on the same content value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM