ลองเขียนโค้ดมาใหม่ค่ะ
โดยแยก Range (m26:m35) เป็นคอลัมน์ เพื่อแยกวางใหม่ในอีกหน้า ซึ่งแต่ละคอลัมน์ที่ต้องการวางไม่ได้อยู่ติดกัน
วางไปเรื่อยๆตามข้อมูลที่คีย์ เข้ามาค่ะ ในที่นี้กำหนดให้วางตั้งแต่แถวที่ 6 ลงไปเรื่อยจนถึงแถวที่ 101 ค่ะ
Code: Select all
Dim rsTemp As Range, arrComment() As Variant, rs As Range
Dim rtAll As Range, rtCol As Range, i As Integer, j As Integer
With Sheets("ER stroke form")
Set rsTemp = .Range("m26,m27,m28,m29,m30,m31,m32,m33,m34,m35")
i = 0
For Each rs In rsTemp
If rs.Value <> "" Then
ReDim Preserve arrComment(i)
arrComment(i) = rs.Value
i = i + 1
End If
Next rs
End With
With Sheets("Table record")
Set rtAll = .Range("ag6:ag101,ah6:ah101,aj6:aj101,am6:am101,ap6:ap101,as6:as101,au6:au101,ax6:ax101,ba6:ba101")
For i = 1 To rtAll.Rows.Count
j = 0
Set rtCol = rtAll.Rows(i)
For Each r In rtCol.Cells
If r.EntireColumn.Hidden = False Then
If r.Comment Is Nothing Then
r.AddComment
r.Comment.Text Text:=arrComment(j)
Else
r.Comment.Text Text:=arrComment(j)
End If
j = j + 1
End If
Next r
Next i
End With
แต่ปรากฎว่าพอกดปุ่มคำสั่งแล้วเกิด Error ค่ะ พอกลับไปใช้โค้ดเดิมก็ไม่เหมือนเดิมแล้ว
ขอคำแนะนำจากอาจารย์และท่านผู้รู้ด้วยนะคะ
ต้องการนำข้อความที่ remark ในช่วง m25:m36 ไปวางอีกชีต (Table record) ในคอลัมน์ที่ต้องการคือ AG,AH,AJ,AM,AP,AS,AU,AX,BA
วางตั้งแต่บรรทัดที่ 6 ถัดไปเรื่อยๆ จนถึง บรรทัดที่ 101 โดยผ่านปุ่มคำสั่ง Save ค่ะ
ขอบพระคุณมากๆค่ะ.
You do not have the required permissions to view the files attached to this post.