Page 1 of 1

การอ่านค่าใน Comment หลายบรรทัด

Posted: Mon Oct 14, 2013 4:34 pm
by beeFGT
ขอทราบการค่าใน Comment หลายบรรทัดใน cell
เราอ่านค่าได้แค่บรรทัดเดียว บรรทัดที่ 2 เป็นต้นไปมองไม่เห็น ไม่ทราบว่าต้นวนลูปอ่านค่ายังไงค่ะ
เพื่อที่จะเก็บค่า comments ทั้งหมด เก็บลง database อีกทีค่ะ

Dim rng As Range

Set rng = Sheets("PSIAuto").Cells(l_Row + l_CountRow + 2, l_Col)

If rng <> "" Then

For Each mycell In rng.Cells
If Not (mycell.Comment Is Nothing) Then

l_Comment = mycell.Comment.Text

End If
Next mycell


End If

ไม่ทราบว่าต้องเขียนโค้ดเพิ่มยังไงค่ะ ช่วยหน่อยค่ะ ติดปัญหาตรงนี้อย่างเดียวค่ะ

Re: การอ่านค่าใน Comment หลายบรรทัด

Posted: Mon Oct 14, 2013 5:01 pm
by snasui
:D แนบไฟล์ตัวอย่างมาด้วยครับ

Re: การอ่านค่าใน Comment หลายบรรทัด

Posted: Tue Oct 15, 2013 9:01 am
by beeFGT
แนบไฟล์ตัวอย่างค่ะ
ต้องการอ่านค่าที่แสดงใน comments ทั้งหมดที่ L8 ,K18, S18 , M28, M47, M74 , M83 , M92, M101 , S101 , ...

เช่น cell L8 รับค่าได้
07-10-2013 11:49:18
=> 50

=> 0

-------------------
cell K18 รับค่าได้
09-10-2013 08:16:02
=> 908
09-10-2013 08:15:52
=> 908

ที่เรารับได้แค่ 07-10-2013 11:49:18 แต่ว่าอ่านมาไม่หมด (=>50 และ =>0) ไม่ทราบว่าต้อง Loop อย่างไรค่ะ

Re: การอ่านค่าใน Comment หลายบรรทัด

Posted: Tue Oct 15, 2013 6:39 pm
by snasui
:D ลองดูตัวอย่างการ Code ตามด้านล่างครับ

Code: Select all

Sub GetCommentText()
    Dim rAll As Range
    Dim r As Range
    Dim rTarget As Range
    With Sheets(2)
        Set rAll = .UsedRange
    End With
    For Each r In rAll
        With Sheets(1)
            Set rTarget = .Range("a" & Rows.Count).End(xlUp).Offset(1, 0)
        End With
        If Not r.Comment Is Nothing Then
            rTarget = r.Comment.Text
            rTarget.Offset(0, 1) = "Sheet " & r.Parent.Name & " Cell " & r.Address
        End If
    Next r
End Sub

Re: การอ่านค่าใน Comment หลายบรรทัด

Posted: Wed Oct 16, 2013 9:32 am
by beeFGT
ขอบคุณมากๆค่ะ ^^