2016-06-10 10 views
0

스크립트가 필요한 작업을 정확히 수행하고 있지만 입력 범위 (A7 : B30)가 기존 형식이 아닌 단일 행으로 삽입됩니다.Excel 데이터 시트 항목이 복수 행이 아닌 단일 행으로 삽입됩니다.

Sub UpdateLogWorksheet() 
    'http://www.contextures.com/xlForm02.html 

    Dim dataWks As Worksheet 
    Dim inputWks As Worksheet 

    Dim nextRow As Long 
    Dim oCol As Long 

    Dim myRng As Range 
    Dim myCopy As String 
    Dim myCell As Range 

    'cells to copy from Input sheet - some contain formulas 
    myCopy = "A7:B30" 

    Set inputWks = Worksheets("Input") 
    Set dataWks = Worksheets("Data") 

    With dataWks 
     nextRow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row 
    End With 

    With inputWks 
     Set myRng = .Range(myCopy) 

    End With 

    With dataWks 
    With .Cells(nextRow, "A") 
     .Value = "" 
     .NumberFormat = "dd/mm/yyyy" 
    End With 
    .Cells(nextRow, "D").Value = "HELLO" 
    oCol = 3 
    For Each myCell In myRng.Cells 
     dataWks.Cells(nextRow, oCol).Value = myCell.Value 
     oCol = oCol + 1 
    Next myCell 
    End With 

    'clear input cells that contain constants 
    With inputWks 
    On Error Resume Next 
    With .Range(myCopy).Cells.SpecialCells(xlCellTypeConstants) 
      .ClearContents 
      Application.GoTo .Cells(1) ', Scroll:=True 
    End With 
    On Error GoTo 0 
    End With 
End Sub 

아이디어가 있으십니까?

답변

0

시도의 변화 :

For Each myCell In myRng.Cells 
    dataWks.Cells(nextRow, oCol).Value = myCell.Value 
    oCol = oCol + 1 
Next myCell 

For Each myCell In myRng.Cells 
    dataWks.Range(myCell.Address).Value = myCell.Value 
Next myCell 

의 배치를 보존하는 것, 즉, 데이터가 복사 된 동일한 범위로 접착한다.