gpt4 book ai didi

excel - 如何记录单元格位置(非空)并为每个单元格运行宏

转载 作者:行者123 更新时间:2023-12-04 22:22:26 26 4
gpt4 key购买 nike

enter image description here enter image description here

大家好,在互联网上搜索了一段时间后,我无法写出标题中描述的任何内容。但是,有没有办法记录那些不为空/空白的单元格的单元格位置(不确定我是否描述正确),然后运行宏仅限 对于每个单元格; 不管他们是否被转移了? 例如(根据屏幕截图),如果 A1、A3 和 A5 不是空白,则仅对这些单元格运行 marco 甚至 如果其中一些稍后转移到 A4 或 A8。 所以简而言之,我真的需要宏只在这些 上运行。单元格如果它不是空白/空。

最佳答案

这是您要查找的代码的原始结构。在您认为合适的情况下使其适应您的项目,并根据需要扩展其功能。

Sub SkipBlanks()

Dim Rl As Long ' last row
Dim Tmp As Variant
Dim R As Long ' row counter

With Worksheets("Sheet1") ' modify to suit
Rl = .Cells(.Rows.Count, "A").End(xlUp).Row
' work on column A
For R = 2 To Rl ' start the loop in row 2
Tmp = .Cells(R, "A").Value
If Len(Tmp) Then
MsgBox "Cell " & Cells(R, "A").Address(0, 0) & _
" has the value """ & Tmp & """.", _
vbInformation, "Test report"
End If
Next R
End With
End Sub

为了快速测试,在 A 列的随机位置添加两个或 3 个值并运行代码。

关于excel - 如何记录单元格位置(非空)并为每个单元格运行宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61419545/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com