2015-01-29 3 views
0

"복사 대상"을 사용하여 하나의 문서에서 다른 문서로 데이터를 전송하려고하는데 클립 보드 사용을 피하고 싶지만 포맷팅을 중단하고 싶습니다 ...VBA 복사 대상 있지만 값으로

Dim Sheet As Worksheet 
Dim FoundLocationSheet As Boolean 
Dim n As Long 
Dim AllSheet As Worksheet 
Set AllSheet = Sheets("Main") 

'Transfer data 
For n = 1 To AllSheet.Cells(Rows.Count, 1).End(xlUp).Row 
    If AllSheet.Cells(n, 1) = "TiTle" Then 
     With Sheets(AllSheet.Cells(n - 1, 1).Value) 
      AllSheet.Cells(n, 1).CurrentRegion.Copy Destination:=.Cells(Rows.Count, 1).End(xlUp).Offset(2, 0) 
     End With 
    End If 
Next n 

매크로 잠재적 A20:L40에서 데이터를 끌어와 A15:L35에 넣어 수 ...

나는 AllSheet.Cells(n, 1).CurrentRegion.Copy Destination:=.Cells(Rows.Count, 1).End(xlUp).Offset(2, 0)와 다른 것들을 많이 시도하고 있었다하지만 그것이 작동되도록하는 방법을 작동하지 않을 수 있습니다. ..

시트 크기는 삭제 형식이 너무 오래 걸린다는 것을 의미합니다./

아이디어가 있으십니까?

답변

1

는 클립 보드피하려고 만 값을 복사 때문에, 당신은 당신은 어떤에 데이터를 복사 할 수이

Sub Demo() 
    Dim Sheet As Worksheet 
    Dim FoundLocationSheet As Boolean 
    Dim n As Long 
    Dim rSource As Range 
    Dim rDest As Range 
    Dim AllSheet As Worksheet 

    Set AllSheet = Sheets("Main") 

    'Transfer data 
    For n = 1 To AllSheet.Cells(Rows.Count, 1).End(xlUp).Row 
     If AllSheet.Cells(n, 1) = "TiTle" Then 
      With Worksheets(AllSheet.Cells(n - 1, 1).Value) 
       ' Reference the range to be copied 
       Set rSource = AllSheet.Cells(n, 1).CurrentRegion 
       ' Reference the Top Left cell of the destination range 
       ' and resize to match source range 
       Set rDest = _ 
        .Cells(.Rows.Count, 1).End(xlUp).Offset(2, 0) _ 
        .Resize(rSource.Rows.Count, rSource.Columns.Count) 
       ' Copy values 
       rDest.Value = rSource.Value 
      End With 
     End If 
    Next n 
End Sub 
0

처럼 Range.Copy

뭔가 대신 Value 속성에 할당을 사용할 수 있습니다 배열에서 배열로 이동합니다. 이렇게하는 코드는 짧고 놀랍도록 효율적입니다. 참고 : 소스에는 둘 이상의 셀이 있어야합니다.

' Create dynamic array 
Dim arr() As Variant 
Dim rg As Range 


Set rg = AllSheet.Cells(n, 1).CurrentRegion 
' Read values to array 
arr = rg.Value 

' Write the values back sheet 
.Cells(Rows.Count, 1).End(xlUp).Offset(2, 0).Value = arr