Sub chuyen_doi_bang()
On Error Resume Next
'tao bang phu
Dim dong_cuoi As Long
dong_cuoi = Sheet1.Range("A" & Rows.Count).End(xlUp).Row
Sheet1.Range("H4").Formula = "=LEN(C4)-LEN(SUBSTITUTE(C4,"","",""""))+1"
Sheet1.Range("H4").Select
Selection.AutoFill Destination:=Range("H4:H" & dong_cuoi), Type:=xlFillDefault
Sheet1.Range("H4:H" & dong_cuoi) = Sheet1.Range("H4:H" & dong_cuoi).Value
Sheet1.Range("I4:I" & dong_cuoi) = Sheet1.Range("C4:C" & dong_cuoi).Value
Sheet1.Range("I4:I" & dong_cuoi).Replace What:=",*", Replacement:=""
'dung mang cho cot E
Dim shData As Worksheet
Dim arrData, arrSoLuong, arrKetQua
Dim e As Long, h As Long, n As Long, r As Long, s As Long
Set shData = Sheet1
e = shData.Range("A" & shData.Rows.Count).End(xlUp).Row
arrData = shData.Range("A4:A" & e).Value
arrSoLuong = shData.Range("H4:H" & e).Value
s = WorksheetFunction.Sum(arrSoLuong)
ReDim arrKetQua(1 To s, 1 To 1)
For r = 1 To UBound(arrData)
For h = 1 To arrSoLuong(r, 1)
n = n + 1
arrKetQua(n, 1) = arrData(r, 1)
Next
Next
shData.Range("E4").Resize(s).Value = arrKetQua
'dung mang cho cot F
Dim arrDataB, arrSoLuongB, arrKetQuaB
Dim eB As Long, hB As Long, nB As Long, rB As Long, sB As Long
eB = shData.Range("A" & shData.Rows.Count).End(xlUp).Row
arrDataB = shData.Range("B4:B" & eB).Value
arrSoLuongB = shData.Range("H4:H" & eB).Value
sB = WorksheetFunction.Sum(arrSoLuongB)
ReDim arrKetQuaB(1 To sB, 1 To 1)
For rB = 1 To UBound(arrDataB)
For hB = 1 To arrSoLuongB(rB, 1)
nB = nB + 1
arrKetQuaB(nB, 1) = arrDataB(rB, 1)
Next
Next
shData.Range("F4").Resize(sB).Value = arrKetQuaB
'dung mang cho cot G
Dim arrDataC, arrSoLuongC, arrKetQuaC
Dim eC As Long, hC As Long, nC As Long, rC As Long, sC As Long
eC = shData.Range("A" & shData.Rows.Count).End(xlUp).Row
arrDataC = shData.Range("I4:I" & eC).Value
arrSoLuongC = shData.Range("H4:H" & eC).Value
sC = WorksheetFunction.Sum(arrSoLuongC)
ReDim arrKetQuaC(1 To sC, 1 To 1)
For rC = 1 To UBound(arrDataC)
For hC = 1 To arrSoLuongC(rC, 1)
nC = nC + 1
arrKetQuaC(nC, 1) = arrDataC(rC, 1)
Next
Next
shData.Range("G4").Resize(sC).Value = arrKetQuaC
'xoa cot H va cot I
Sheet1.Range("H4:I" & dong_cuoi).ClearContents
End Sub