![]() |
#2
adffdda2016-03-25 15:23
Sub Macro4()
Dim wb As Workbook, sh As Worksheet, c As Range, r As Range, rng As Range, lr As Long Dim a, b, d As Object, i& Set d = CreateObject("scripting.dictionary") a = Array("a", "b") b = Array("c", "d") For i = 0 To UBound(a) d(a(i)) = b(i) Next Application.ScreenUpdating = False Set sh = ActiveSheet Set rng = Range("F4:X4").SpecialCells(xlCellTypeConstants, 2) Set wb = GetObject(ThisWorkbook.Path & "\Book.xls") With wb.Sheets(1) lr = .[a65536].End(xlUp).Row - 2 With .Rows(2) For Each r In rng Set c = .Find(d(r.Value), , , 1) If Not c Is Nothing Then c.Offset(1).Resize(lr).Copy sh.Cells(65536, r.Column).End(xlUp).Offset(1) End If Next End With End With wb.Close False Application.ScreenUpdating = True End Sub Sub Macro5() Dim wb As Workbook, sh As Worksheet, c As Range, r As Range, rng As Range, lr As Long Dim a, b, d As Object, i& Set d = CreateObject("scripting.dictionary") a = Array("a", "b") b = Array("c", "d") For i = 0 To UBound(a) d(a(i)) = b(i) Next Application.ScreenUpdating = False Set sh = ActiveSheet Set rng = Range("A4:X4") rng.Select Set wb = GetObject(ThisWorkbook.Path & "\Book.xls") With wb.Sheets(1) lr = .[a65536].End(xlUp).Row - 2 With .Rows(2) For Each r In rng t = d(r.Value) If t <> "" Then Set c = .Find(d(r.Value), , , 1) If Not c Is Nothing Then c.Offset(1).Resize(lr).Copy sh.Cells(65536, r.Column).End(xlUp).Offset(1) End If Next End With End With wb.Close False Application.ScreenUpdating = True End Sub Sub Macro6() Dim wb As Workbook, sh As Worksheet, c As Range, r As Range, rng As Range, lr As Long Dim a, b, d As Object, i& Set d = CreateObject("scripting.dictionary") a = Array("a", "b") b = Array("c", "d") For i = 0 To UBound(a) d(a(i)) = b(i) Next Application.ScreenUpdating = False Set sh = ActiveSheet Set rng = Range("A4:X4") rng.Select Set wb = GetObject(ThisWorkbook.Path & "\Book.xls") j = sh.UsedRange.Find("*", , -4163, , 1, 2).Row + 1 With wb.Sheets(1) lr = .[a65536].End(xlUp).Row - 2 With .Rows(2) For Each r In rng t = d(r.Value) If t <> "" Then Set c = .Find(d(r.Value), , , 1) If Not c Is Nothing Then c.Offset(1).Resize(lr).Copy sh.Cells(j, r.Column) End If Next End With End With wb.Close False Application.ScreenUpdating = True End Sub [此贴子已经被作者于2016-3-25 15:42编辑过] |
Dim wb As Workbook, c As Range, r As Range, rng As Range, lr As Long
Application.ScreenUpdating = False
Set rng = Range("F4:I4,N4:O4,Q4:R4,W4:X4")
Set wb = GetObject(ThisWorkbook.Path & "\Book.xls")
With wb.Sheets(1)
lr = .[a65536].End(xlUp).Row - 2
With .Rows(2)
For Each r In rng
Set c = .Find(r.Value, , , 1)
If Not c Is Nothing Then
c.Offset(1).Resize(lr).Copy r.Offset(1)
End If
Next
End With
End With
wb.Close False
Application.ScreenUpdating = True
End Sub
Sub Macro2()
Dim wb As Workbook, sh As Worksheet, c As Range, r As Range, rng As Range, lr As Long
Application.ScreenUpdating = False
Set sh = ActiveSheet
Set rng = Range("F4:I4,N4:O4,Q4:R4,W4:X4")
Set wb = GetObject(ThisWorkbook.Path & "\Book.xls")
With wb.Sheets(1)
lr = .[a65536].End(xlUp).Row - 2
With .Rows(2)
For Each r In rng
Set c = .Find(r.Value, , , 1)
If Not c Is Nothing Then
c.Offset(1).Resize(lr).Copy sh.Cells(65536, r.Column).End(xlUp).Offset(1)
End If
Next
End With
End With
wb.Close False
Application.ScreenUpdating = True
End Sub
Sub Macro3()
Dim wb As Workbook, sh As Worksheet, c As Range, r As Range, rng As Range, lr As Long, m&
Application.ScreenUpdating = False
Set sh = ActiveSheet
Set rng = Range("F4:I4,N4:O4,Q4:R4,W4:X4")
Set wb = GetObject(ThisWorkbook.Path & "\Book.xls")
With wb.Sheets(1)
lr = .[a65536].End(xlUp).Row - 2
With .Rows(2)
For Each r In rng
Set c = .Find(r.Value, , , 1)
If Not c Is Nothing Then
m = sh.Cells(65536, r.Column).End(xlUp).Row + 1
If m > 5 Then m = m + 2
c.Offset(1).Resize(lr).Copy sh.Cells(m, r.Column)
End If
Next
End With
End With
wb.Close False
Application.ScreenUpdating = True
End Sub
[此贴子已经被作者于2016-3-25 15:22编辑过]