Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2205|回复: 7

[已解决]求一有关批注的赋值部分的代码

[复制链接]
发表于 2012-12-10 16:37 | 显示全部楼层 |阅读模式
本帖最后由 jhtjj 于 2012-12-10 16:54 编辑

求一VBA代码,要求能够达到如下功能:
第一、VBA代码运行后,能够读入单元格区域;
第二、根据第一读入的单元格逐个判断,如果有批注的,删除批注,如果没有批注的,添加批注;
第三、在第二添加批注后,对添加的批注内容显示该单元格的内容。(就这个不会,就是代码中的 'x.Comment = x
。)
(本人的目的是:想把单元格的内容赋值给批注,待以后处理完单元格的内容,再把批注赋值回单元格
。)具体见下面代码:
Option Explicit
Sub 测试()
Dim rng, x As Range
Set rng = Application.InputBox("请使用鼠标选择单元格区域:", , , , , , , 8)
For Each x In rng
    If x.Comment Is Nothing Then
        x.AddComment
        'x.Comment = x
    Else
        x.ClearComments
    End If
Next x
End Sub

最佳答案
2012-12-10 17:39
也可以不用CSTR函数,
  1. .Text x.Value & ""
复制代码
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2012-12-10 17:29 | 显示全部楼层
  1. Application.DisplayCommentIndicator = xlCommentAndIndicator
复制代码
显示所有批注。
回复

使用道具 举报

发表于 2012-12-10 17:30 | 显示全部楼层
Application.DisplayCommentIndicator 属性
返回或设置单元格显示批注和标识符的方式。可以是 XlCommentDisplayMode 常量之一。
语法

表达式.DisplayCommentIndicator

表达式   一个代表 Application 对象的变量。

回复

使用道具 举报

发表于 2012-12-10 17:30 | 显示全部楼层
XlCommentDisplayMode 枚举
指定单元格显示批注和批注标识符的方式。
版本信息
已添加版本:  Excel 2007

名称 值 说明
xlCommentAndIndicator 1 任何时候都显示批注和标识符。
xlCommentIndicatorOnly -1 只显示标识符。鼠标指针在单元格上移动时显示批注。
xlNoIndicator 0 任何时候都不显示批注也不显示标识符。
回复

使用道具 举报

发表于 2012-12-10 17:34 | 显示全部楼层
本帖最后由 hwc2ycy 于 2012-12-10 17:37 编辑
  1. Option Explicit
  2. Sub 测试()
  3.     Dim rng, x As Range
  4.     Set rng = Application.InputBox("请使用鼠标选择单元格区域:", , , , , , , 8)
  5.     For Each x In rng
  6.         If x.Comment Is Nothing Then
  7.             With x.AddComment
  8.                 .Text CStr(x.Value)
  9.             End With
  10.         Else
  11.             x.ClearComments
  12.         End If
  13.     Next x
  14.     Application.DisplayCommentIndicator = xlCommentAndIndicator
  15. End Su
复制代码
回复

使用道具 举报

发表于 2012-12-10 17:35 | 显示全部楼层
QQ五笔截图未命名.png
回复

使用道具 举报

发表于 2012-12-10 17:35 | 显示全部楼层
Application.DisplayCommentIndicator = xlCommentAndIndicator
可根据需要可要可不要。
回复

使用道具 举报

发表于 2012-12-10 17:39 | 显示全部楼层    本楼为最佳答案   
也可以不用CSTR函数,
  1. .Text x.Value & ""
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-3-29 07:24 , Processed in 0.771206 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表