Nguyen Anh Dung
Board Regular
- Joined
- Feb 28, 2020
- Messages
- 180
- Office Version
- 2016
- Platform
- Windows
i have code as below:
when run wrong, help me edit code run column A with row boder red is result column C
Tổ 3 Khu Phố 3
Tổ 1 Khu Phố 3
Tổ 38 Khu Phố 3
Thanks you!!!
Code:
Sub Tach3()
Dim i&, j&, Lr&, t&, k&, R&, C&, D&
Dim Arr(), KQ, Temp
With Sheets("Sheet1")
Lr = .Cells(Rows.Count, 1).End(xlUp).Row
Arr = .Range("A2:A" & Lr).Value
DDANH = .Range("H2:I14").Value
R = UBound(Arr): D = UBound(DDANH)
ReDim KQ(1 To R, 1 To 6)
For i = 1 To R
Temp = Split(Arr(i, 1), ",")
C = UBound(Temp)
For j = 0 To C
If IsNumeric(Left(Temp(j), 1)) Then KQ(i, 1) = Temp(j)
If UCase(Trim(Temp(j))) Like UCase((DDANH(1, 1)) & "*") Then KQ(i, 2) = Temp(j)
For k = 3 To D
If k < 5 Then If UCase(Trim(Temp(j))) Like UCase((DDANH(k, 1)) & "*") Then KQ(i, 2) = KQ(i, 2) & Temp(j)
If k = 5 Then If UCase(Trim(Temp(j))) Like UCase((DDANH(5, 1)) & "*") Then KQ(i, 3) = Temp(j)
If k > 5 Then If UCase(Trim(Temp(j))) Like UCase((DDANH(k, 1)) & "*") Then KQ(i, DDANH(k, 2)) = Temp(j)
Next k
Next j
Next i
.Range("B2").Resize(R, 6) = KQ
End With
End Sub
Tổ 3 Khu Phố 3
Tổ 1 Khu Phố 3
Tổ 38 Khu Phố 3
Thanks you!!!