emgaingayngo
Thành viên hoạt động



- Tham gia
- 9/2/07
- Bài viết
- 141
- Được thích
- 5
Trong VBA các bạn chỉ giúp dùm emgaingayngo câu lệnh để đưa nhiều phần tử vào trong một comment. Các bạn xem file nha. Thanks!
Sub MyComment()
Dim TextComment As String
TextComment = ""
''=======================================================
Sheets("Sheet1").Select
Range("A1:J10").Select
''=======================================================
For Each Clls In Selection
TextComment = TextComment & IIf(IsNull(Clls) Or Clls.Text = "", "", "+") & Clls.Text
Next
''=======================================================
Range("A12").Select
Selection.ClearComments
Range("A12").AddComment
Range("A12").Comment.Visible = False
Range("A12").Comment.Text Text:=TextComment
Range("A12").Select
End Sub
Trong VBA các bạn chỉ giúp dùm emgaingayngo câu lệnh để đưa nhiều phần tử vào trong một comment. Các bạn xem file nha. Thanks!
Function ComExist(Cell As Range) As Boolean
On Error Resume Next
ComExist = CBool(Len(Cell.Comment.Application) > 0)
End Function
Sub AddCom()
Dim Cell As Range, Comm As Comment
With Sheet1
If ComExist(.Range("A12")) = False Then .Range("A12").AddComment
Set Comm = .Range("A12").Comment
Comm.Text (" ")
For Each Cell In .Range("A1:J10")
If Cell.Text <> "" Then
Comm.Text (Comm.Text & " _ " & Cell.Text)
End If
Next
End With
Comm.Text (Mid$(Comm.Text, 5, Len(Comm.Text)))
Set Cell = Nothing
End Sub
To ca_dafi : Bây giờ làm sao cho độ rộng của comment vừa với các giá trị được add vào và chỉnh cho font chữ =10 ?
''' Dinh dang
Comm.Shape.Select True
With Selection.Font
.Name = "Times New Roman"
.FontStyle = "Regular"
.Size = 10
Selection.AutoSize = True
End With
Sub AddCom()
Dim Cell As Range, Comm As Comment
With Sheet1
If ComExist(.Range("A12")) = False Then .Range("A12").AddComment
Set Comm = .Range("A12").Comment
Comm.Text (" ")
For Each Cell In .Range("A1:J10")
If Cell.Text <> "" Then
Comm.Text (Comm.Text & " _ " & Cell.Text)
End If
Next
End With
Comm.Text (Mid$(Comm.Text, 5, Len(Comm.Text)))
''' Dinh dang
Comm.Shape.Select True
With Selection.Font
.Name = "Times New Roman"
.FontStyle = "Regular"
.Size = 10
Selection.AutoSize = True
End With
Set Cell = Nothing
End Sub