返回列表 上一主題 發帖

[發問] i甚麼時候+數 , 又怎樣可以變回零又到相關位置再次計算?

本帖最後由 stillfish00 於 2014-2-14 14:09 編輯

回復 1# joslau
參考:
  1. Sub Test()
  2.   Dim rngSource As Range, rngTarget As Range
  3.   Dim ar, i As Long, j As Long
  4.   
  5.   With Sheets("Sheet1")
  6.     Set rngSource = .[A1].CurrentRegion.Resize(, 3) '來源
  7.     Set rngTarget = .[G1].Resize(rngSource.Rows.Count, 3) '合併結果
  8.    
  9.     '刪除舊的結果
  10.     If rngTarget.Cells(1).Value <> "" Then rngTarget.Cells(1).CurrentRegion.ClearContents
  11.    
  12.     '合併
  13.     ar = rngSource.Value  '一次性取出
  14.     For i = 1 To UBound(ar)
  15.       If ar(i, 1) <> "" Then
  16.         j = j + 1
  17.         rngTarget.Cells(j, 1).Resize(, 3) = Application.Index(ar, i)
  18.       Else
  19.         rngTarget.Cells(j, 3).Value = rngTarget.Cells(j, 3).Value & "," & ar(i, 3)
  20.       End If
  21.     Next
  22.   End With
  23. End Sub
複製代碼

TOP

        靜思自在 : 自己害自己,莫過於亂發脾氣。
返回列表 上一主題