Excel 用 vba 批量插入/提取批注

批量插入批注

Sub 批量插入批注()
On Error Resume Next

    '批注来源列名
    Dim targetColumnName As String
    '批注来源列号
    Dim offsetColumn As Integer
    '计数
    Dim count As Integer
    
    targetColumnName = InputBox("直接输入列名字母: ", "批注来源列")
    If targetColumnName = "" Then
        GoTo gotoEnd
    End If
    
    '算出目标列号
    offsetColumn = Range("A1:" & targetColumnName & "1").Cells.count
    
    '遍历所选列,从目标列对应行中取值插入为批注
    For Each sel In Selection
        With sel
            If Not Cells(sel.Row, offsetColumn) = "" Then
                .ClearComments
                .AddComment
                .Comment.Text Text:=Cells(sel.Row, offsetColumn).Value
                .Comment.Visible = False
                count = count + 1
            End If
        End With
    Next
    
    MsgBox "批量插入批注 " & count & "个", vbOKOnly, "批量批注完成"
    
gotoEnd:

End Sub

批量提取批注

Sub 批量提取批注()
On Error Resume Next

    '批注存放列名
    Dim targetColumnName As String
    '向左偏移几列取值
    Dim offsetColumn As Integer
    '计数
    Dim count As Integer
    
    targetColumnName = InputBox("直接输入列名字母: ", "批注内容接受列")
    If targetColumnName = "" Then
        GoTo gotoEnd
    End If
    
    '算出目标列号
    offsetColumn = Range("A1:" & targetColumnName & "1").Cells.count
    
    
    '遍历所选列,从目标列对应行中取值插入为批注
    For Each sel In Selection
        With sel
            If Not .Comment.Text = "" Then
                Cells(sel.Row, offsetColumn).Value = .Comment.Text
                .ClearComments
                count = count + 1
            End If
        End With
    Next
    
    MsgBox "批量提取批注 " & count & "个", vbOKOnly, "批量提取完成"
    
gotoEnd:

End Sub
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

笑虾

多情黯叹痴情癫。情癫苦笑多情难

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值