从另一个单元格区域的值创建对单元格区域的注释 [英] Create comments to a range of cells ftom the values of another range of cells

查看:62
本文介绍了从另一个单元格区域的值创建对单元格区域的注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为一系列单元格创建注释.注释中应包含其他单元格区域的值.

I want to create comments to a range of cells. The comments should contain the values of another range of cells.

这是我到目前为止所拥有的:

Here is what I have so far:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim sResult As String

If Union(Target, Range("A18")).Address = Target.Address Then
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    sResult = "Maximal " & Target.Value

    With Range("I6")
        .ClearComments
        .AddComment
        .Comment.Text Text:=sResult
    End With
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End If
End Sub

这适用于一个单元格.我需要一系列的单元格.例如,假设在单元格A21:F40的注释中需要单元格A1:F20的值.我不想多次复制同一Sub.

This works for one cell. I need this for a range of cells. For example, let's say I need the values of cells A1:F20 in comments of cells A21:F40. I do not want to copy the same Sub as many times.

推荐答案

如果更换,应该做的事

With Range("I6")
        .ClearComments
        .AddComment
        .Comment.Text Text:=sResult
    End With

使用

    For Each cell In Range("A1", "F20").Cells
    Dim V As Range
    Set V = cell.Offset(20, 0)
    With cell
    .ClearComments
    If Not IsEmpty(V) Then
    .AddComment V.Value
    End If
    End With
   Next

这将基本上忽略所有空单元格.

This will basically ignore all empty cells.

输出:

我的代码:

Sub TEST()
 For Each cell In Range("A1", "F20").Cells
    Dim V As Range
    Set V = cell.Offset(20, 0)
    With cell
    .ClearComments
    If Not IsEmpty(V) Then
    .AddComment V.Value
    End If
    End With
   Next
End Sub

这篇关于从另一个单元格区域的值创建对单元格区域的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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