2014-12-15 5 views
0

데이터를 하나의 시트로 집계하기 위해 통합 문서를 반복합니다. 다양한 소스 시트의 데이터는 항상 동일한 열에 있지만 행은 다양합니다. 나는 값을 할당하고 있지만 조건부 서식은 여전히 ​​나오고있다.VBA는 서식없이 값을 할당합니다.

기본적으로 한 책에서 다른 책으로 값을 복사하여 붙여 넣는 가장 빠른 방법은 무엇입니까? 화면 업데이트가 꺼져 있습니다.

For Each sheet In Workbooks(filename).Worksheets 
     If sheet.Name = "Template" Then 
      lastrow = sheet.Range("A" & Rows.Count).End(xlUp).row 
      For row = 2 To lastrow 
       All.Range("A" & All_nextrow).Value = sheet.Range("A" & row).Value 
       All.Range("B" & All_nextrow).Value = sheet.Range("B" & row).Value 
       All.Range("C" & All_nextrow).Value = sheet.Range("C" & row).Value 
       All.Range("D" & All_nextrow).Value = sheet.Range("D" & row).Value 
       All.Range("E" & All_nextrow).Value = sheet.Range("E" & row).Value 
       All.Range("F" & All_nextrow).Value = sheet.Range("F" & row).Value 
       All.Range("G" & All_nextrow).Value = sheet.Range("G" & row).Value 
       All.Range("H" & All_nextrow).Value = sheet.Range("H" & row).Value 
       All.Range("I" & All_nextrow).Value = sheet.Range("I" & row).Value 
       All.Range("J" & All_nextrow).Value = sheet.Range("J" & row).Value 
       All.Range("K" & All_nextrow).Value = sheet.Range("K" & row).Value 
       All.Range("L" & All_nextrow).Value = Workbooks(filename).Name 
       All_nextrow = All_nextrow + 1 
      Next row 
     End If 
    Next sheet 
+0

그건 ... 이상합니다. 나는'.Value'가 변형 인 줄 알았는데 누군가 틀렸다면 정정 해 주겠지 만 형식 데이터를 저장할 수 없어야합니다. 조건부 형식의 추가 규칙이 다른 항목에서 남지 않았다고 확신합니까? – BobbitWormJoe

+0

'.Value'를 사용하여 서식을 복사하지 않으므로 여기에 다른 것이 있습니다. –

+0

시트의 빈 셀에 셀 서식을 확인하십시오. – peege

답변

0

귀하가 찾고있는 것일 수 있습니다. 필요한 코드에 몇 가지 문제가 있습니다.

이 예제에서는이 시트를 넣을 시트의 이름으로 "모두"를 사용하고 있습니다.

이 코드는 Range와 실제 열 이름을 사용하는 열을 통과하는 간단한 루프를 사용하며 열 L에 도달 할 때까지 Cells (lRow, lCol) 및 루프를 사용합니다. 패턴을 바꾼다.

IF 문을 사용하여 "템플리트"만 사용하기 때문에 각 워크 시트에 대해 제거했습니다. 따라서 원하는 모든 것을 찾을 수 있도록 루프를 반복 할 필요가 없습니다. 그 이상의 것을 사용하고자한다면 If Sheet.Name = "Template"이 필요합니다.

이 코드를 한 번 작성하고 필요에 맞게 수정하십시오. 나는 당신이 어떤 결함이라도 논평하면 대답을 수정 해 드리겠습니다.

Sub DataAggregate() 

Dim sheet As String 
Dim all As String 
Dim allRow As Long 

    all = "All" 'whatever the name of "ALL" is, set here. 
    allRow = 2 

    sheet = "Template" 

    lastRow = Sheets(sheet).Range("A" & Rows.Count).End(xlUp).row 
     For lRow = 2 To lastRow 
      For lCol = 1 To 11 
       Sheets(all).Cells(allRow,lCol) = Sheets(sheet).Cells(lRow, lCol).Text 
      Next lCol 

      Sheets(all).Cells(allRow, "L") = sheet 'or filename' 'confused as to what you want 
      allRow = allRow + 1 
     Next lRow 
    Next ws 
End Sub 
0

나는 당신이 필요로 이해 모르겠어요하지만 당신은 A2와 L {lastrow} 사이의 모든 셀을 복사하려면 다음을 사용할 수 있습니다

lastrow = SheetFrom.Range("A" & Rows.Count).End(xlUp).Row 
SheetFrom.Range("A2:L" & lastrow).Copy 
SheetTo.Range("A2").PasteSpecial (xlPasteValues) 
0
Sub CopyPaste() 
Dim WorkbookToCopy As Workbook 
Dim WorkbookToPaste As Workbook 
Dim RowCount As Integer 

Set WorkbookToCopy = Workbook1 'Workbook to copy name like Workbook1 
Set WorkbookToPaste = Workbook2 
RowCount = 1  ' 'clean' row in WorkbookToPaste 
For Each Sheet In Workbook1 
    For Each Column In Sheet 
    RowCount = 1 
     For Each Cell In Column 
      WorkbookToPaste.Sheets(Sheet).Cells(RowCount, Column).Value = Cell.Value 
      RowCount = RowCount + 1 
     Next 
    Next 
Next 
End Sub 

난 그 작업을 확신 할 수는 없지만 매크로에 사용할 수있는 논리를 보여 드리고자합니다.

관련 문제