识别活动单元格偏移是否包含注释

huangapple go评论99阅读模式
英文:

Identify if activecell offset contains a comment

问题

无法在任何地方找到答案。

我正在尝试运行一个代码,该代码通过一系列的单元格 AL3:AZ201,并且如果其中一个单元格包含 'X',则查看活动单元格左侧34个单元格并查看它是否与活动单元格左侧17个单元格不同,如果不同,则更改为与活动单元格左侧17个单元格相同的值。

我遇到困难的条件是,我希望代码能够判断如果活动单元格左侧34个单元格包含注释,那么跳过此单元格并转到下一个单元格。

所以举个例子:单元格AO3中有一个 'X',单元格G3 (0,-34) 和单元格X3 (0,-17) 不相同,所以期望将G3转换为X3的值,但是单元格G3有一个分配给它的注释,所以不应该被覆盖,但令人恼火的是它仍然被覆盖。

出于某种原因,它似乎只是无论注释单元格如何都会被覆盖。任何帮助都将不胜感激:

英文:

can't seem to find the answer anywhere.

I'm trying to run a code that runs through a range of cells AL3:AZ201 and if one of these cells contains and 'X' then look at the cell 34 cells to the left of the active cell and see if it is different to the cell 17 cells to the left of the active cell, if it is then change to the value of the cell 17 cells to the left of the active cell.

The condition I am struggling with is that I want the code to say if the cell 34 cells to the left of the active cell contains a comment, then skip this and go to the next cell.

So as an example: Cell AO3 has an 'X' in it, cell G3 (0,-34) and cell X3 (0,-17) are not the same so would expectantly convert G3 to value X3, however cell G3 has a comment assigned to it so should not be overwritten, but it still does get overwritten annoyingly.

For some reason it just seems to be overwriting regardless of the comment cells. Any help is appreciated:

识别活动单元格偏移是否包含注释

  1. Sub MoveCellsIfDifferent()
  2. Dim ws As Worksheet
  3. Dim rng As Range
  4. Dim cell As Range
  5. Dim targetCell As Range
  6. ' Set the worksheet and range variables
  7. Set ws = ThisWorkbook.Worksheets("Sheet1") ' Replace "Sheet1" with your actual sheet name
  8. Set rng = ws.Range("AL3:AZ201")
  9. ' Loop through each cell in the range
  10. For Each cell In rng
  11. ' Check if the cell is not blank
  12. If Not IsEmpty(cell.Value) Then
  13. ' Check if the cell contains "X"
  14. If cell.Value = "X" Then
  15. ' Get the cell 34 cells to the left
  16. Set targetCell = cell.Offset(, -34)
  17. ' Check if the cell 34 cells to the left has a comment
  18. If Not targetCell.comment Is Nothing Then
  19. ' Skip to the next cell
  20. Exit For
  21. End If
  22. ' Check if the cell 34 cells to the left is different from the cell 17 cells to the left
  23. If targetCell.Value <> cell.Offset(, -17).Value Then
  24. ' Replace the value of the cell 17 cells to the left with the value of the cell 34 cells to the left
  25. cell.Offset(, -34).Value = cell.Offset(, -17).Value
  26. End If
  27. End If
  28. End If
  29. Next cell
  30. End Sub

答案1

得分: 2

找到了 - 而不是

  1. 如果目标单元格.Comment 不为空,则

你需要

  1. 如果目标单元格.CommentThreaded 不为空,则
英文:

Found it - instead of

  1. If Not targetCell.Comment Is Nothing Then

You need

  1. If Not targetCell.CommentThreaded Is Nothing Then

huangapple
  • 本文由 发表于 2023年7月10日 18:57:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76653031.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定