help edit code vba split

Nguyen Anh Dung

Board Regular
Joined
Feb 28, 2020
Messages
180
Office Version
  1. 2016
Platform
  1. Windows
i have code as below:
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
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


1635606954896.png

Thanks you!!!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,215,507
Messages
6,125,212
Members
449,214
Latest member
mr_ordinaryboy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top