標題:
[發問]
大量資料篩選不重複並分類
[打印本頁]
作者:
uf023630
時間:
2011-5-14 17:15
標題:
大量資料篩選不重複並分類
我遇到大量資料須要分開處理,想請大家幫忙
[attach]6168[/attach]
作者:
diabo
時間:
2011-5-15 06:57
本帖最後由 diabo 於 2011-5-15 07:00 編輯
'問題1
end_row = Sheets("ASD1").[A65536].End(xlUp).Row
For Each aaa In Array("DL", "BA", "STOCK")
With Sheets("ASD1")
.Range("A1:C" & end_row).AutoFilter Field:=2, Criteria1:="=" & aaa
.Range("A1:C" & end_row).SpecialCells(xlCellTypeVisible).Copy
Sheets(aaa).Range("A1").PasteSpecial Paste:=xlPasteValues
End With
Next
複製代碼
作者:
diabo
時間:
2011-5-15 07:00
記得在 VBE中設定引用項目勾選 Microsoft ActiveX Data Objects 2.x Library
'問題2
Dim strConn As String, strSQL As String
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
strConn = "Driver={Microsoft Excel Driver (*.xls)};" & _
"DBQ=" + ThisWorkbook.FullName + ";" & _
"ReadOnly=True"
Set conn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
strSQL = "SELECT ITNO, SUM(TQT) AS TQT2 From ((SELECT ITNO,TQT FROM [ASD1$] WHERE LEN(WHS)=6 ORDER BY ITNO) tmpTable) GROUP BY ITNO"
conn.Open strConn
rs.Open strSQL, conn, 3, 1
With Sheets("BFTTL")
.Range("A2:B" & .[A65536].End(xlUp).Row).Cells.ClearContents
.Cells(2, 1).CopyFromRecordset rs
End With
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
複製代碼
作者:
diabo
時間:
2011-5-15 07:01
看不懂問題3
作者:
oobird
時間:
2011-5-15 16:53
問題3
Sub yy()
Dim d As Object, a, b, i&, j%, k%, m%, n%
Set d = CreateObject("Scripting.Dictionary")
k = 1
With Sheets("ASD1")
a = .Range(.[a2], .[c65536].End(3))
ReDim b(1 To UBound(a), 1 To 3)
For i = 1 To UBound(a)
If Len(a(i, 2)) = 6 Then
m = m + 1
For j = 1 To 3
b(m, j) = a(i, j)
Next
End If
Next
Do
For i = 1 To m
If b(i, 2) <> "" Then
If Not d.exists(b(i, 1)) Then
d(b(i, 1)) = Array(b(i, 1) & "", b(i, 2), b(i, 3))
b(i, 2) = "": n = n + 1
End If
End If
Next
If d.Count > 0 Then
Sheets("BF12").Cells(1, k).Resize(, 3) = .[a1:c1].Value
Sheets("BF12").Cells(2, k).Resize(d.Count, 3) = Application.Transpose(Application.Transpose(d.items))
d.RemoveAll
k = k + 3
End If
Loop Until n = m
End With
End Sub
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)