Board logo

標題: 快速合併相同的欄位 [打印本頁]

作者: 198188    時間: 2012-11-9 23:00     標題: 快速合併相同的欄位

處理前
20110113        1202
20110113        1202
20110113        1202
20110113        1401
20110113        1401
20110113        1401
20110113        1401
20110113        1401
20110113        1401
20110113        1401
20110113        2101
20110113        2101
20110113        2101
20110113        2101
20110113        2101
處理後
20110103        1201,1202
20110105        1201
20110106        1201,1202,1401,2101,2201,2301,2601,2701
20110107        1201,1202
20110110        1201,1202
20110111        1201
20110112        1201
20110113        1201,1202,1401,2101


Private Sub cmdClear_Click()
    Sheet2.Cells.Clear
End Sub

Public Sub cmdCompareab_Click()
    Dim n As Integer '欄位數
    Dim count_a As Double  '資料ab的筆數
    Dim temp As String
    Dim my_range
   
   
    Sheet2.Activate
    count_a = Sheet2.Range("a1").End(xlDown).Row
    n = Sheet2.Range("a1").End(xlToRight).Column


    Sheet1.Activate
    m = Sheet1.Range("b3")  '合併第m個欄位
    a = 1
    b = 0
    c = Sheet1.Range("b2")
    calc_field1 = Sheet1.Range("b4")
    calc_field2 = Sheet1.Range("b5")
    is_sort = Sheet1.Range("b6")
    is_merger = Sheet1.Range("b7")
   
     symbol = Sheet1.Range("b1") '合併符號
   
    If (UCase(is_sort) = "Y") Then
        Sheet2.Activate
        
    ActiveSheet.Range(ActiveSheet.Cells(1, 1), ActiveSheet.Cells(count_a, n)).Sort Key1:=ActiveSheet.Cells(2, c), Order1:=xlAscending, Key2:=ActiveSheet.Cells( _
        2, m), Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase _
        :=False, Orientation:=xlTopToBottom, SortMethod:=xlStroke, DataOption1:= _
        xlSortNormal, DataOption2:=xlSortNormal
    End If

    Sheet1.Activate
   
    Sheet3.Cells.Clear
   
   
   

    For j = 1 To n
        Sheet3.Cells(1, j) = Sheet2.Cells(1, j)
    Next




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)