Có cách nào khác mà không cần gõ tên sheet không bạnFor each wsName In Array(tên sheet1, tên sheet 2, ...)
... INDEX(WorkSheets(wsName).Range(...), MATCH(WorkSheets(wsName).Range(...)...)
Next wsName




Có cách nào khác mà không cần gõ tên sheet không bạn
dữ liệu nhiều sheet chẳng lẻ mỗi lần thêm sheet hay đổi tên sheet đều sửa code
cám ơn bạn nhiều.
For Each ws In Worksheets
If ws.Name <> "ABC" Then
'......
End If
Next
Chưa ai giải đành phải chờ thôi!!!!!
Public Sub GPE()
Dim sArr(), dArr(), I As Long, J As Long, DK As String, Dic As Object, Tem As String, CoL As Long, Ws As Worksheet
Set Dic = CreateObject("Scripting.Dictionary")
sArr = Range([A14], [A14].End(xlDown)).Value
DK = [G12].Value
ReDim dArr(1 To UBound(sArr, 1), 1 To 2)
For I = 1 To UBound(sArr, 1)
Tem = sArr(I, 1)
If Not Dic.exists(Tem) Then
Dic.Add Tem, I
dArr(I, 1) = 1
Else
dArr(Dic.Item(Tem), 1) = dArr(Dic.Item(Tem), 1) + 1
End If
Next I
For Each Ws In Worksheets
If Ws.Name <> "KH" Then
CoL = Ws.[J4].End(xlToRight).Column - 1
sArr = Ws.Range(Ws.[B4], Ws.[B65536].End(xlUp)).Resize(, CoL).Value
For I = 7 To UBound(sArr, 1)
If sArr(I, 1) = DK Then
For J = 9 To UBound(sArr, 2)
Tem = sArr(1, J)
If Dic.exists(Tem) Then dArr(Dic.Item(Tem), 2) = sArr(I, J)
Next J
End If
Next I
End If
Next Ws
[F14].Resize(UBound(dArr, 1), 2) = dArr
Set Dic = Nothing
End Sub
Anh Ba Te có thể hổ trợ em lần nữa nhaChờ thì phải chờ rồi nhưng đừng viết bài Spam như bài #4.
Có khi người đọc cố hiểu xem người viết muốn cái gì qua diễn đạt "không dễ hiểu như vầy".
Và còn nhiều lý do để số lượng đọc thì nhiều nhưng chưa ai trả lời bài viết.
--------------
Dựa vào cách đọc hiểu công thức trong cột G của bạn, tôi "mù mờ" hiểu là như vầy,
Bạn xem trong file, Thay đổi ô G12 để xem kết quả.PHP:Public Sub GPE() Dim sArr(), dArr(), I As Long, J As Long, DK As String, Dic As Object, Tem As String, CoL As Long, Ws As Worksheet Set Dic = CreateObject("Scripting.Dictionary") sArr = Range([A14], [A14].End(xlDown)).Value DK = [G12].Value ReDim dArr(1 To UBound(sArr, 1), 1 To 2) For I = 1 To UBound(sArr, 1) Tem = sArr(I, 1) If Not Dic.exists(Tem) Then Dic.Add Tem, I dArr(I, 1) = 1 Else dArr(Dic.Item(Tem), 1) = dArr(Dic.Item(Tem), 1) + 1 End If Next I For Each Ws In Worksheets If Ws.Name <> "KH" Then CoL = Ws.[J4].End(xlToRight).Column - 1 sArr = Ws.Range(Ws.[B4], Ws.[B65536].End(xlUp)).Resize(, CoL).Value For I = 7 To UBound(sArr, 1) If sArr(I, 1) = DK Then For J = 9 To UBound(sArr, 2) Tem = sArr(1, J) If Dic.exists(Tem) Then dArr(Dic.Item(Tem), 2) = sArr(I, J) Next J End If Next I End If Next Ws [F14].Resize(UBound(dArr, 1), 2) = dArr Set Dic = Nothing End Sub
[COLOR=#007700][FONT=monospace]For [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Each Ws In Worksheets
[/FONT][/COLOR][COLOR=#007700][FONT=monospace]If [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Ws[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Name [/FONT][/COLOR][COLOR=#007700][FONT=monospace]<> [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"KH" [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Then
CoL [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Ws[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]J4[/FONT][/COLOR][COLOR=#007700][FONT=monospace]].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]End[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]xlToRight[/FONT][/COLOR][COLOR=#007700][FONT=monospace]).[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Column [/FONT][/COLOR][COLOR=#007700][FONT=monospace]- [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]1
sArr [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Ws[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Range[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Ws[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]B4[/FONT][/COLOR][COLOR=#007700][FONT=monospace]], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Ws[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]B65536[/FONT][/COLOR][COLOR=#007700][FONT=monospace]].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]End[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]xlUp[/FONT][/COLOR][COLOR=#007700][FONT=monospace])).[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Resize[/FONT][/COLOR][COLOR=#007700][FONT=monospace](, [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]CoL[/FONT][/COLOR][COLOR=#007700][FONT=monospace]).[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Value
[/FONT][/COLOR][COLOR=#007700][FONT=monospace]For [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]I [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]7 To UBound[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sArr[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]1[/FONT][/COLOR][COLOR=#007700][FONT=monospace])
If [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sArr[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]I[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]1[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) = [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]DK Then
[/FONT][/COLOR][COLOR=#007700][FONT=monospace]For [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]J [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]9 To UBound[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sArr[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]2[/FONT][/COLOR][COLOR=#007700][FONT=monospace])
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Tem [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sArr[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]1[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]J[/FONT][/COLOR][COLOR=#007700][FONT=monospace])
If [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Dic[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]exists[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Tem[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Then dArr[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Dic[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Item[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Tem[/FONT][/COLOR][COLOR=#007700][FONT=monospace]), [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]2[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) = [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sArr[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]I[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]J[/FONT][/COLOR][COLOR=#007700][FONT=monospace])
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Next J
End [/FONT][/COLOR][COLOR=#007700][FONT=monospace]If
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Next I
End [/FONT][/COLOR][COLOR=#007700][FONT=monospace]If
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Next Ws
[/FONT][/COLOR][COLOR=#007700][FONT=monospace][[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]F14[/FONT][/COLOR][COLOR=#007700][FONT=monospace]].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Resize[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]UBound[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]dArr[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]1[/FONT][/COLOR][COLOR=#007700][FONT=monospace]), [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]2[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) = [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]dArr
Set Dic [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Nothing
End Sub
Anh Ba Te có thể hổ trợ em lần nữa nha
Em cần dò tìm kế quả cột G thôi không cần điếm số lượng ở cột F
[/FONT][/COLOR]Mã:[COLOR=#007700][FONT=monospace]For [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Each Ws In Worksheets [/FONT][/COLOR][COLOR=#007700][FONT=monospace]If [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Ws[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Name [/FONT][/COLOR][COLOR=#007700][FONT=monospace]<> [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"KH" [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Then CoL [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Ws[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]J4[/FONT][/COLOR][COLOR=#007700][FONT=monospace]].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]End[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]xlToRight[/FONT][/COLOR][COLOR=#007700][FONT=monospace]).[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Column [/FONT][/COLOR][COLOR=#007700][FONT=monospace]- [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]1 sArr [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Ws[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Range[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Ws[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]B4[/FONT][/COLOR][COLOR=#007700][FONT=monospace]], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Ws[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]B65536[/FONT][/COLOR][COLOR=#007700][FONT=monospace]].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]End[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]xlUp[/FONT][/COLOR][COLOR=#007700][FONT=monospace])).[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Resize[/FONT][/COLOR][COLOR=#007700][FONT=monospace](, [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]CoL[/FONT][/COLOR][COLOR=#007700][FONT=monospace]).[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Value [/FONT][/COLOR][COLOR=#007700][FONT=monospace]For [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]I [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]7 To UBound[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sArr[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]1[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) If [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sArr[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]I[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]1[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) = [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]DK Then [/FONT][/COLOR][COLOR=#007700][FONT=monospace]For [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]J [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]9 To UBound[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sArr[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]2[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Tem [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sArr[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]1[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]J[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) If [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Dic[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]exists[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Tem[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Then dArr[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Dic[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Item[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Tem[/FONT][/COLOR][COLOR=#007700][FONT=monospace]), [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]2[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) = [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sArr[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]I[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]J[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Next J End [/FONT][/COLOR][COLOR=#007700][FONT=monospace]If [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Next I End [/FONT][/COLOR][COLOR=#007700][FONT=monospace]If [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Next Ws [/FONT][/COLOR][COLOR=#007700][FONT=monospace][[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]F14[/FONT][/COLOR][COLOR=#007700][FONT=monospace]].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Resize[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]UBound[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]dArr[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]1[/FONT][/COLOR][COLOR=#007700][FONT=monospace]), [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]2[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) = [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]dArr Set Dic [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Nothing End Sub
Private Sub CommandButton1_Click()
Dim sArr(), dArr(1 To 50000, 1 To 5), Ws As Worksheet, I As Long, J As Long, K As Long
For Each Ws In ThisWorkbook.Worksheets
If Ws.Name <> "KH" Then
sArr = Ws.Range(Ws.[J4], Ws.[J4].End(xlToRight)).Resize(5).Value
For J = 1 To UBound(sArr, 2)
K = K + 1
For I = 1 To 5
dArr(K, I) = sArr(I, J)
Next I
Next J
End If
Next Ws
Sheets("KH").[A14:E50000].ClearContents
Sheets("KH").[A14].Resize(K, 5) = dArr
End Sub
Public Sub GPE()
Dim sArr(), dArr(), I As Long, J As Long, DK As String, Dic As Object, Tem As String, CoL As Long, Ws As Worksheet
Set Dic = CreateObject("Scripting.Dictionary")
sArr = Range([A14], [A14].End(xlDown)).Value
DK = [G12].Value
ReDim dArr(1 To UBound(sArr, 1), 1 To 1)
For I = 1 To UBound(sArr, 1)
Tem = sArr(I, 1)
If Not Dic.exists(Tem) Then Dic.Add Tem, I
Next I
For Each Ws In Worksheets
If Ws.Name <> "KH" Then
CoL = Ws.[J4].End(xlToRight).Column - 1
sArr = Ws.Range(Ws.[B4], Ws.[B65536].End(xlUp)).Resize(, CoL).Value
For I = 7 To UBound(sArr, 1)
If sArr(I, 1) = DK Then
For J = 9 To UBound(sArr, 2)
Tem = sArr(1, J)
If Dic.exists(Tem) Then dArr(Dic.Item(Tem), 1) = sArr(I, J)
Next J
End If
Next I
End If
Next Ws
[G14:G50000].ClearContents
[G14].Resize(UBound(dArr, 1)) = dArr
Set Dic = Nothing
End Sub




chắc anh BaTe chạy mất dép quá, bạn chạy không được có nghĩa làCám ơn Anh Rất nhiều
Anh cho em hỏi thêm nha
Tại sao copy code vào file của anh gửi thì nó chạy còn vào file của em thì nó không chạy
Trường hợp em thêm 3 điều kiện nữa thì sữa như thế nào
DK = [G12:J12].Value
Em tìm ra rồi thì ra thiếu đoạn code nàyCám ơn Anh Rất nhiều
Anh cho em hỏi thêm nha
Tại sao copy code vào file của anh gửi thì nó chạy còn vào file của em thì nó không chạy
Trường hợp em thêm 3 điều kiện nữa thì sữa như thế nào
DK = [G12:J12].Value
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$G$12" Then GPE
End Sub
rivate Sub CommandButton1_Click()
Dim sArr(), dArr(), I As Long, J As Long, DK As String, Dic As Object, Tem As String, CoL As Long, Ws As Worksheet
Set Dic = CreateObject("Scripting.Dictionary")
sArr = Range([B10], [B10].End(xlDown)).Value
[COLOR=#ff0000]DK = [E4].Value[/COLOR]
ReDim dArr(1 To UBound(sArr, 1), 1 To 1)
For I = 1 To UBound(sArr, 1)
Tem = sArr(I, 1)
If Not Dic.exists(Tem) Then Dic.Add Tem, I
Next I
For Each Ws In Worksheets
If Ws.Name <> "KH" And Ws.Name <> "CELL" Then
CoL = Ws.[J4].End(xlToRight).Column - 1
sArr = Ws.Range(Ws.[B4], Ws.[B65536].End(xlUp)).Resize(, CoL).Value
For I = 7 To UBound(sArr, 1)
If sArr(I, 1) = DK Then
For J = 9 To UBound(sArr, 2)
Tem = sArr(1, J)
If Dic.exists(Tem) Then dArr(Dic.Item(Tem), 1) = sArr(I, J)
Next J
End If
Next I
End If
Next Ws
[COLOR=#ff0000][E10].Resize(UBound(dArr, 1)) = dArr[/COLOR]
Set Dic = Nothing
End Sub

Chạy macro ghi lại copy từng cái quaNhờ các anh chỉ dùm đoạn code này cần sửa chỗ nào chạy được
Mã:rivate Sub CommandButton1_Click() Dim sArr(), dArr(), I As Long, J As Long, DK As String, Dic As Object, Tem As String, CoL As Long, Ws As Worksheet Set Dic = CreateObject("Scripting.Dictionary") sArr = Range([B10], [B10].End(xlDown)).Value [COLOR=#ff0000]DK = [E4].Value[/COLOR] ReDim dArr(1 To UBound(sArr, 1), 1 To 1) For I = 1 To UBound(sArr, 1) Tem = sArr(I, 1) If Not Dic.exists(Tem) Then Dic.Add Tem, I Next I For Each Ws In Worksheets If Ws.Name <> "KH" And Ws.Name <> "CELL" Then CoL = Ws.[J4].End(xlToRight).Column - 1 sArr = Ws.Range(Ws.[B4], Ws.[B65536].End(xlUp)).Resize(, CoL).Value For I = 7 To UBound(sArr, 1) If sArr(I, 1) = DK Then For J = 9 To UBound(sArr, 2) Tem = sArr(1, J) If Dic.exists(Tem) Then dArr(Dic.Item(Tem), 1) = sArr(I, J) Next J End If Next I End If Next Ws [COLOR=#ff0000][E10].Resize(UBound(dArr, 1)) = dArr[/COLOR] Set Dic = Nothing End Sub
Private Sub CommandButton1_Click()
Dim Sh As Worksheet
For Each Sh In Worksheets
If Sh.Name <> "KH" And Sh.Name <> "CELL" Then
Sh.[J3:IV65000].Sort Sh.[3:3], 1, Orientation:=xlLeftToRight
End If
Next
End Sub
cũng được nhưng nhiều sheet thì sauChạy macro ghi lại copy từng cái qua
Mã:Private Sub CommandButton1_Click() Dim Sh As Worksheet For Each Sh In Worksheets If Sh.Name <> "KH" And Sh.Name <> "CELL" Then Sh.[J3:IV65000].Sort Sh.[3:3], 1, Orientation:=xlLeftToRight End If Next End Sub
Mình muốn lộc dữ liệu tất cả các sheet qua sheet Cell
Kết quả trả về các ô em tô màu vàng(trong file dinh kèm)
Các anh xem file đính kèm

Bài này hay nè copy về để sau này có cần để dùngBấm nút Update trong sheet GPE thử xem.
Nhập lại từ E4:T4 những gì bạn muốn, tôi nhập thủ công để thử code thôi.
Dữ liệu lớn nên giảm bớt màu mè, hình vẽ, Conditional Formatting... Cần thiết lắm thì sử dụng đúng trong phạm vi dữ liệu thôi, sao lại tô màu cả cột, cả dòng "bao la" cho phí của.
Không biết nói gì hơn ngoài câu cám ơn rất nhiều.Bấm nút Update trong sheet GPE thử xem.
Nhập lại từ E4:T4 những gì bạn muốn, tôi nhập thủ công để thử code thôi.
Dữ liệu lớn nên giảm bớt màu mè, hình vẽ, Conditional Formatting... Cần thiết lắm thì sử dụng đúng trong phạm vi dữ liệu thôi, sao lại tô màu cả cột, cả dòng "bao la" cho phí của.