返回列表 上一主題 發帖

[發問] 如何簡化巨集

回復 1# luke

請上傳EXCEL壓縮檔,並說明所需之功能要求

TOP

本帖最後由 register313 於 2012-4-1 23:14 編輯

回復 3# luke
  1. Sub XX()
  2. Set Rng = Union([A15:K15], [A22:K22], [A29:K29], [A36:K36])
  3. For Each R In Rng
  4.     Set s = Sheets("Sheet2").[A:A].Find(R, , , xlWhole)
  5.     If Not s Is Nothing Then
  6.        R.Resize(6, 1) = Application.Transpose(s.Resize(1, 6))
  7.     End If
  8. Next
  9. End Sub
複製代碼

TOP

本帖最後由 register313 於 2012-4-1 23:36 編輯

回復 5# Hsieh

若儲存格為數字但並非字典裡的關鍵字,該如何防錯
  1. Sub nn()
  2. Set d = CreateObject("Scripting.Dictionary")
  3. With sheet2
  4.    For Each a In .Range(.[A1], .[A1].End(xlDown))
  5.       d(a.Value) = a.Offset(, 1).Resize(, 5).Value
  6.    Next
  7. End With
  8. With sheet1
  9. For Each a In .UsedRange.SpecialCells(xlCellTypeConstants, xlNumbers)
  10.    If d.Exists(a.Value) Then
  11.       a.Offset(1).Resize(UBound(d(a.Value), 2), 1) = Application.Transpose(d(a.Value))
  12.    End If
  13. Next
  14. End With
  15. End Sub
複製代碼

TOP

        靜思自在 : 唯其尊重自己的人,才更勇於縮小自己。
返回列表 上一主題