hoituong1020
Thành viên mới
- Tham gia
- 8/12/15
- Bài viết
- 46
- Được thích
- 0
Chào các anh/chị trong diễn đàn!
Tôi có file excel trích xuất dữ liệu ở các sheet vào sheet tổng hợp thì bị báo lỗi code không trích xuất được dữ liệu. Lúc đầu thì trích xuất được nhưng sau ko trích xuất được dữ liệu. Code của tôi như sau:
Sub DSDTTB()
Dim ws As Worksheet
Dim lr As Long, j As Long, r As Long, k As Long, i As Byte
Dim arr As Variant, kq As Variant, DK As Boolean
Dim BD As Long, ED As Long, dktienbo As String
With Sheet4
BD = CLng(.Range("V4").Value)
ED = CLng(.Range("V5").Value)
dktienbo = CByte(UCase(.Range("V6").Value))
.Range("A11:W" & WorksheetFunction.Max(11, .Cells(Rows.Count, "A").End(xlUp).Row)).ClearContents
End With
For Each ws In Sheets
If CByte(Right(ws.CodeName, 1)) >= 6 Or CByte(Right(ws.CodeName, 1)) <= 1 Then
lr = lr + ws.Cells(Rows.Count, "B").End(xlUp).Row
End If
Next ws
ReDim kq(1 To (Sheets.Count - 4) * 10, 1 To Columns("AC").Column)
For Each ws In Sheets
If CByte(Right(ws.CodeName, 1)) >= 6 Or CByte(Right(ws.CodeName, 1)) <= 1 Then
lr = ws.Cells(Rows.Count, "A").End(xlUp).Row
arr = ws.Range("B11:AC" & lr).Value
For j = 1 To UBound(arr, 1)
DK = CLng(arr(j, 1)) >= BD And CLng(arr(j, 1)) <= ED And CByte(arr(j, Columns("Y").Column - 1)) = dktienbo
If DK Then
k = k + 1
kq(k, 1) = ws.Name
kq(k, 2) = arr(j, 1)
kq(k, 3) = arr(j, 2)
For i = 4 To UBound(arr, 2) - 4
kq(k, i) = arr(j, i + 4)
Next i
End If
Next j
Erase arr
End If
Next ws
If k >= 1 Then
Sheet4.Range("a11").Resize(k, Columns("W").Column).Value = kq
Erase kq
End If
Set ws = Nothing
End Sub
Sub DSDTTB()
Dim ws As Worksheet
Dim lr As Long, j As Long, r As Long, k As Long, i As Byte
Dim arr As Variant, kq As Variant, DK As Boolean
Dim BD As Long, ED As Long, dktienbo As String
With Sheet4
BD = CLng(.Range("V4").Value)
ED = CLng(.Range("V5").Value)
dktienbo = CByte(UCase(.Range("V6").Value))
.Range("A11:W" & WorksheetFunction.Max(11, .Cells(Rows.Count, "A").End(xlUp).Row)).ClearContents
End With
For Each ws In Sheets
If CByte(Right(ws.CodeName, 1)) >= 6 Or CByte(Right(ws.CodeName, 1)) <= 1 Then
lr = lr + ws.Cells(Rows.Count, "B").End(xlUp).Row
End If
Next ws
ReDim kq(1 To (Sheets.Count - 4) * 10, 1 To Columns("AC").Column)
For Each ws In Sheets
If CByte(Right(ws.CodeName, 1)) >= 6 Or CByte(Right(ws.CodeName, 1)) <= 1 Then
lr = ws.Cells(Rows.Count, "A").End(xlUp).Row
arr = ws.Range("B11:AC" & lr).Value
For j = 1 To UBound(arr, 1)
DK = CLng(arr(j, 1)) >= BD And CLng(arr(j, 1)) <= ED And CByte(arr(j, Columns("Y").Column - 1)) = dktienbo
If DK Then
k = k + 1
kq(k, 1) = ws.Name
kq(k, 2) = arr(j, 1)
kq(k, 3) = arr(j, 2)
For i = 4 To UBound(arr, 2) - 4
kq(k, i) = arr(j, i + 4)
Next i
End If
Next j
Erase arr
End If
Next ws
If k >= 1 Then
Sheet4.Range("a11").Resize(k, Columns("W").Column).Value = kq
Erase kq
End If
Set ws = Nothing
End Sub
bị báo lỗi ở dòng:
DK = CLng(arr(j, 1)) >= BD And CLng(arr(j, 1)) <= ED And CByte(arr(j, Columns("Y").Column - 1)) = dktienbo
Mong các anh/chị giúp dùm.
Tôi có file excel trích xuất dữ liệu ở các sheet vào sheet tổng hợp thì bị báo lỗi code không trích xuất được dữ liệu. Lúc đầu thì trích xuất được nhưng sau ko trích xuất được dữ liệu. Code của tôi như sau:
Sub DSDTTB()
Dim ws As Worksheet
Dim lr As Long, j As Long, r As Long, k As Long, i As Byte
Dim arr As Variant, kq As Variant, DK As Boolean
Dim BD As Long, ED As Long, dktienbo As String
With Sheet4
BD = CLng(.Range("V4").Value)
ED = CLng(.Range("V5").Value)
dktienbo = CByte(UCase(.Range("V6").Value))
.Range("A11:W" & WorksheetFunction.Max(11, .Cells(Rows.Count, "A").End(xlUp).Row)).ClearContents
End With
For Each ws In Sheets
If CByte(Right(ws.CodeName, 1)) >= 6 Or CByte(Right(ws.CodeName, 1)) <= 1 Then
lr = lr + ws.Cells(Rows.Count, "B").End(xlUp).Row
End If
Next ws
ReDim kq(1 To (Sheets.Count - 4) * 10, 1 To Columns("AC").Column)
For Each ws In Sheets
If CByte(Right(ws.CodeName, 1)) >= 6 Or CByte(Right(ws.CodeName, 1)) <= 1 Then
lr = ws.Cells(Rows.Count, "A").End(xlUp).Row
arr = ws.Range("B11:AC" & lr).Value
For j = 1 To UBound(arr, 1)
DK = CLng(arr(j, 1)) >= BD And CLng(arr(j, 1)) <= ED And CByte(arr(j, Columns("Y").Column - 1)) = dktienbo
If DK Then
k = k + 1
kq(k, 1) = ws.Name
kq(k, 2) = arr(j, 1)
kq(k, 3) = arr(j, 2)
For i = 4 To UBound(arr, 2) - 4
kq(k, i) = arr(j, i + 4)
Next i
End If
Next j
Erase arr
End If
Next ws
If k >= 1 Then
Sheet4.Range("a11").Resize(k, Columns("W").Column).Value = kq
Erase kq
End If
Set ws = Nothing
End Sub
Sub DSDTTB()
Dim ws As Worksheet
Dim lr As Long, j As Long, r As Long, k As Long, i As Byte
Dim arr As Variant, kq As Variant, DK As Boolean
Dim BD As Long, ED As Long, dktienbo As String
With Sheet4
BD = CLng(.Range("V4").Value)
ED = CLng(.Range("V5").Value)
dktienbo = CByte(UCase(.Range("V6").Value))
.Range("A11:W" & WorksheetFunction.Max(11, .Cells(Rows.Count, "A").End(xlUp).Row)).ClearContents
End With
For Each ws In Sheets
If CByte(Right(ws.CodeName, 1)) >= 6 Or CByte(Right(ws.CodeName, 1)) <= 1 Then
lr = lr + ws.Cells(Rows.Count, "B").End(xlUp).Row
End If
Next ws
ReDim kq(1 To (Sheets.Count - 4) * 10, 1 To Columns("AC").Column)
For Each ws In Sheets
If CByte(Right(ws.CodeName, 1)) >= 6 Or CByte(Right(ws.CodeName, 1)) <= 1 Then
lr = ws.Cells(Rows.Count, "A").End(xlUp).Row
arr = ws.Range("B11:AC" & lr).Value
For j = 1 To UBound(arr, 1)
DK = CLng(arr(j, 1)) >= BD And CLng(arr(j, 1)) <= ED And CByte(arr(j, Columns("Y").Column - 1)) = dktienbo
If DK Then
k = k + 1
kq(k, 1) = ws.Name
kq(k, 2) = arr(j, 1)
kq(k, 3) = arr(j, 2)
For i = 4 To UBound(arr, 2) - 4
kq(k, i) = arr(j, i + 4)
Next i
End If
Next j
Erase arr
End If
Next ws
If k >= 1 Then
Sheet4.Range("a11").Resize(k, Columns("W").Column).Value = kq
Erase kq
End If
Set ws = Nothing
End Sub
bị báo lỗi ở dòng:
DK = CLng(arr(j, 1)) >= BD And CLng(arr(j, 1)) <= ED And CByte(arr(j, Columns("Y").Column - 1)) = dktienbo
Mong các anh/chị giúp dùm.