所以我有一些代碼可以根據旁邊的資訊對單元格進行評論,并且它幾乎可以完美地作業。但是,我遇到了一個問題,它可以處理整個作業簿中的所有作業表,而不是像預期的那樣只處理作業表 3。我僅在 VBA 專案中在第 3 頁上設定了此代碼。所以我的問題是我如何只在一張紙上完成這項作業?這是我的代碼
Private Sub Worksheet_Calculate()
ActiveSheet.UsedRange.ClearComments
Dim targetRng As Range, commentSrcRng As Range
Dim strPrefix As String 'string Prefix
Set targetRng = Application.Range("D16,D18,D20,D22,D24,D26,D28,D30,D32,D34,D36,D38")
Set commentSrcRng = targetRng.Offset(0, 1)
Dim cel As Range
Dim i As Long
i = 1
For Each cel In targetRng
If cel <> "" Then
cel.AddComment
cel.Comment.Visible = False
cel.Comment.Shape.TextFrame.AutoSize = True
cel.Comment.Text strPrefix & commentSrcRng.Cells(i)
End If
i = i 2
Next
uj5u.com熱心網友回復:
但是,我在處理整個作業簿中的所有作業表時遇到問題
那是因為你已經將它編碼為在 ActiveSheet
要參考事件編碼的作業表,請使用 Me
Private Sub Worksheet_Calculate()
Me.UsedRange.ClearComments
Dim targetRng As Range, commentSrcRng As Range
Dim strPrefix As String 'string Prefix
Set targetRng = Me.Range("D16,D18,D20,D22,D24,D26,D28,D30,D32,D34,D36,D38")
Set commentSrcRng = targetRng.Offset(0, 1)
Dim cel As Range
Dim i As Long
i = 1
For Each cel In targetRng
If cel <> "" Then
cel.AddComment
cel.Comment.Visible = False cel.Comment.Shape.TextFrame.AutoSize = True
cel.Comment.Text strPrefix & commentSrcRng.Cells(i)
End If
i = i 2
Next
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/399058.html
上一篇:將pandas日期列轉換為excel之類的文本通用格式
下一篇:maat網站下載資料庫
