Xin chỉ câu lệnh để add nhiều fần tử vào trong 01 comment? (2 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

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!
 

File đính kèm

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!

PHP:
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

Bạn xem thêm file đính kèm nhé.
 

File đính kèm

Upvote 0
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!

Bạn xem nhé :

PHP:
Function ComExist(Cell As Range) As Boolean
    On Error Resume Next
    ComExist = CBool(Len(Cell.Comment.Application) > 0)
End Function
PHP:
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

Thân!
 

File đính kèm

Upvote 0
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 ?
 
Upvote 0
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 ?

Bạn thay đổi chút xíu : Thêm vào

PHP:
    ''' Dinh dang
    Comm.Shape.Select True
    With Selection.Font
        .Name = "Times New Roman"
        .FontStyle = "Regular"
        .Size = 10
        Selection.AutoSize = True
    End With
Thành :

PHP:
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
Thân!
 
Upvote 0
Web KT

Bài viết mới nhất

Back
Top Bottom