snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Sub Button1_Click()
Dim wsDB As Worksheet, wsRes As Worksheet
Set wsDB = Worksheets("Database")
Set wsRes = Worksheets("Results")
Dim iLastRow As Integer
iLastRow = wsDB.Cells(wsDB.Rows.Count, "A").End(xlUp).Row
Dim iAddRow As Integer
iAddRow = 2
Dim arrParams() As String, arrGoods() As String
Dim iLength As Integer, strGoodsID As String
Dim i As Integer, j As Integer
With wsDB
For i = 2 To iLastRow
arrParams() = Split(.Range("BD" & i).Value2, "#" & "#") 'ติดปัญหาตรงนี้เลย
iLength = GetArrLength(arrParams)
For j = 0 To iLength - 1
If Trim(arrParams(j)) <> "" Then
arrGoods() = Split(arrParams(j), "#")
strGoodsID = Trim(arrGoods(0))
.Range("A" & i & ":BC" & i).Copy
With wsRes
.Cells(iAddRow, "A").PasteSpecial xlPasteValues
.Cells(iAddRow, "BE").Value2 = strGoodsID
End With
iAddRow = iAddRow + 1
End If
Next j
Next i
End With
End Sub
Public Function GetArrLength(a As Variant) As Long
If IsEmpty(a) Then
GetArrLength = 0
Else
GetArrLength = UBound(a) - LBound(a) + 1
End If
End Function
โค้ดที่ผมใช้ประมาณนี้ครับ เเละไฟล์ตัวอย่างครับ
You do not have the required permissions to view the files attached to this post.