我有一個代碼,它組合了 C:F 列中所有單元格的單元格內容,并將其放入 B 列的注釋中 - 每行。我現在只需要將其應用于在其各自的 A 列中有內容的行。
單元格A2里面有東西,所以把C2:F2的內容放到B2的注釋中。單元格 A3 中沒有任何內容,因此不要向該單元格添加注釋。單元格A4又有東西了,所以把C4:F4的內容放到B4的注釋中。
該表看起來像這樣:表
到目前為止,我的代碼如下所示:
Sub Test()
Dim LRow As Integer
With ActiveSheet
For LRow = 2 To Range("A" & Rows.Count).End(xlUp).Row
Range(Cells(LRow, 3), Cells(LRow, 6)).Select
Dim c As Range, s As String
With Cells(LRow, 2)
.ClearComments
For Each c In Selection
'If c.Offset(0, -2) <> "" Then
'On Error Resume Next
If c <> "" Then s = IIf(s = "", c, s & Chr(10) & c)
Next c
.AddCommentThreaded "Test:" & Chr(10) & s
End With
s = ""
Next LRow
End With
End Sub
現在的問題是我無法在 A 列中檢查內容。任何人都有關于如何讓那一點作業的任何提示?
uj5u.com熱心網友回復:
嘗試類似下面的內容。還要檢查如何避免選擇以及為什么使用 long 而不是整數
Sub Test()
Dim LRow As Long, aCell As Range, ws As Worksheet
Set ws = ActiveSheet
With ws
For LRow = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
If .Cells(LRow, 1).Value <> "" Then
Dim theComment As String
theComment = ""
For Each aCell In Intersect(Range("C:F"), .Rows(LRow)).Cells
theComment = theComment & aCell.Value
Next aCell
With .Cells(LRow, 2)
.ClearComments
.AddCommentThreaded "Test:" & Chr(10) & theComment
End With
End If
Next LRow
End With
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/397058.html
上一篇:VBA在數字上轉換時間
