返回列表 上一主題 發帖

[發問] 資料轉移

回復 2# ounmaxz


    看不出單位如何對應先以"單位"代表
  1. Sub nn()
  2. Dim Rng As Range, A As Range, Ar(), Ay()
  3. With Sheet2
  4. Set Rng = .Range(.[N5], .[N7].End(xlUp)) '設置比對的標準區域
  5. With Sheet1
  6. ReDim Preserve Ay(0)
  7. Ay(0) = .[A1].Resize(, 14).Value
  8. For Each A In .Range(.[A1], .[A65536].End(xlUp)) '在sheet1的d欄資料循環
  9.     If Not Rng.Find(A, lookat:=xlWhole) Is Nothing And A.Offset(, 13) = "加班" Then '如果標準區找到d欄的值
  10.        ReDim Preserve Ar(s)
  11.        ReDim Preserve Ay(s + 1)
  12.        Ar(s) = Array("單位", A.Value, A.Offset(, 1).Value, "", A.Offset(, 2).Value, Format(A.Offset(, 3).Value, "hh:mm"), Format(A.Offset(, 4).Value, "hh:mm"), A.Offset(, 5).Value)
  13.        Ay(s + 1) = A.Resize(, 14).Value
  14.        s = s + 1
  15.     End If
  16. Next
  17. End With
  18. .[A5:I20] = ""
  19. Sheet3.Cells = "" '清空Sheet3內容
  20. If s > 0 Then .[A5].Resize(s, 8) = Application.Transpose(Application.Transpose(Ar)): _
  21. Sheet3.[A1].Resize(s + 1, 14) = Application.Transpose(Application.Transpose(Ay)) '把Sheet1符合的列複製到Sheet3的A1
  22. End With
  23. End Sub
複製代碼
學海無涯_不恥下問

TOP

回復 4# ounmaxz
  1. Sub nn()
  2. Dim Rng As Range, A As Range, Ar(), Ay()
  3. With Sheet2
  4. Ut = .[P5].Value
  5. Set Rng = .Range(.[N5], .[N65536].End(xlUp)) '設置比對的標準區域
  6. With Sheet1
  7. ReDim Preserve Ay(0)
  8. Ay(0) = .[A1].Resize(, 14).Value
  9. For Each A In .Range(.[A1], .[A65536].End(xlUp)) '在sheet1的d欄資料循環
  10.     If Not Rng.Find(A, lookat:=xlWhole) Is Nothing And A.Offset(, 13) = "加班" Then '如果標準區找到d欄的值
  11.        ReDim Preserve Ar(s)
  12.        ReDim Preserve Ay(s + 1)
  13.        Ar(s) = Array(Ut, A.Value, A.Offset(, 1).Value, "", A.Offset(, 2).Value, Format(A.Offset(, 3).Value, "hh:mm"), Format(A.Offset(, 4).Value, "hh:mm"), A.Offset(, 5).Value)
  14.        Ay(s + 1) = A.Resize(, 14).Value
  15.        s = s + 1
  16.     End If
  17. Next
  18. End With
  19. .[A5:I20] = ""
  20. Sheet3.Cells = "" '清空Sheet3內容
  21. If s > 0 Then .[A5].Resize(s, 8) = Application.Transpose(Application.Transpose(Ar)): _
  22. Sheet3.[A1].Resize(s + 1, 14) = Application.Transpose(Application.Transpose(Ay)) '把Sheet1符合的列複製到Sheet3的A1
  23. End With
  24. End Sub

  25. Sub yy() '填滿日期
  26. y = InputBox("輸入西元年度", , 2010)
  27. With Sheet1
  28. Ar = .[B2:C17].Value
  29. r = 2
  30. For i = DateValue(y & "/1/1") To DateValue(y & "/12/31")
  31.   .Cells(r, 1).Resize(16, 1) = i
  32.   .Cells(r, 2).Resize(16, 2) = Ar
  33.   r = r + 16
  34. Next
  35. End With
  36. End Sub
複製代碼
學海無涯_不恥下問

TOP

        靜思自在 : 能幹不幹,不如苦幹實幹。
返回列表 上一主題