遍历范围并清除要评估的单元格下方的8个单元格的内容 [英] Loop through range and clear contents of 8 cells below the cell being evaluated

查看:45
本文介绍了遍历范围并清除要评估的单元格下方的8个单元格的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想遍历$ C $ 29到$ G $ 29的单元格,如果这些单元格包含空白,我想清除下面8个单元格的内容.例如,如果$ G $ 29为空,我想清除$ G $ 30:$ G $ 37中的内容.我在下面附加了代码.但是我相信.ClearContents行有问题,这与我尝试相对引用的方式有关.谢谢!

I want to loop through cells $C$29 to $G$29 and if the cells contain an empty space I want to clear the contents of the 8 cells below. For example if $G$29 is empty, I want to clear the contents in $G$30:$G$37. I have attached code below. But I believe there is something wrong with the .ClearContents line, something to do with the way I am attempting to reference relatively. Thank you!

最好,M

Sub Hide_Financing()

Dim r As Range

For Each r In Sheet2.Range("$C$29:$G$29")
    If r.Value = "" Then
        Sheet2.Range(r.Address & ":" & r.Offset(rowOffset:=8).Address).ClearContents
    End If
Next r

End Sub

推荐答案

对我来说很好.在您的代码中,无处设置"sheet2"的值.您设置正确吗?您其余的代码是正确的.另一个问题,您是否确定已清除"$ C $ 29:$ G $ 29"范围内的至少一个单元格?

It works fine for me. In your code, nowhere you've set the value of "sheet2". Have you set it correctly? The rest of your code is right. Another question, are you sure that you have cleared at least one cell in the range "$C$29:$G$29" ?

这篇关于遍历范围并清除要评估的单元格下方的8个单元格的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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