返回列表 上一主題 發帖

[發問] 利用EXCEL巨集資料處理

我覺得這個 Case 不使用 Dictionary 反而可能會更快呢, 程式如下 :

Sub Ex()
    Dim i%, j%, iSou%, iRes%, Text$
    Dim rC As Range
   
    Sheets("Result").Range("A2:G65536").Clear
   
    iRes = 2
    With Sheets("Date")
      iSou = .Range("B65536").End(xlUp).Row
      
      For j = 2 To iSou
      ' 這邊原想要套用 Join 方法但搭配 Cells 一直都說 "執行錯誤", 所以只能暫時先這樣用囉.
      Text = .Cells(j, 2) & "-" & .Cells(j, 3) & "-" & .Cells(j, 4) & "-" & .Cells(j, 5) & "-" & .Cells(j, 6)
               
        With Sheets("Result")
          Set rC = .Range(.Cells(2, 7), .Cells(iRes, 7)).Find(Text, LookIn:=xlValues)
         
          If Not rC Is Nothing Then
            i = rC.Row
            .Cells(i, 6) = .Cells(i, 6) + 1
          Else
            .Cells(iRes, 7) = Text
            .Cells(iRes, "A").Resize(, 5) = Split(Text, "-")
            .Cells(iRes, 6) = 1
            iRes = iRes + 1
          End If
        
        End With
      Next j
      
    End With
  Sheets("Result").Range("G2:G65536").Clear
End Sub

TOP

        靜思自在 : 我們要做好社會的環保,也要做好內心的環保。
返回列表 上一主題