2014-06-12 2 views
0

나는 다른 워크 시트의 데이터를 가져와 워크 시트 당 별도의 열로 가져 오는 Excel 시트가 있습니다. 내 열에서 중복 된 것을 찾고 모든 복제본을 삭제하려고합니다. 예를 들어 코드 세 개가있는 경우 세 개 중 하나가 12GB로 남기를 원합니다. 얼마나 많은 고유 한 값이 (자동으로) 있는지 계산하고 그래프를 자동으로 채울 수 있도록 이것을 원합니다. 나는 이것을하기 위해 많은 다른 수식을 시도했지만 VBA 코드가 필요하다고 생각하고 있습니다. 그러나 나는 그 코딩을 사용하지 않으므로 무엇을 해야할지 잘 모릅니다. 아래는 나의 Excel 시트의 세 열의 예입니다. 이미지를 게시 할 수 없습니다/그래서이 솔루션의 큰 팬이 아니에요이이 특정 열 및 게재 위치에 의존하는 hackish 매크로입니다)셀은 삭제하지만 행은 삭제하지 않습니다.

12gb  sdf  vfg 
22rg  tttyhg dsf 
dfg455  ggff df 
fgfg  fff  vcs 
4redd  ccv  dfgh 
56ff  66hg 66y 
yygf  66y  56ff 
66ygt  yggfg 12gb 
ghhg   
      vfg  
+2

일회성 일 경우 ... 수동으로 3 개의 열을 만드십시오 1. 그런 다음 데이터 중복을 사용하십시오. 그런 다음 1 열을 3에 넣으십시오.이 작업을 여러 번 수행해야하는 경우 매크로를 기록하십시오. 이렇게. – xQbert

+0

어떤 Excel 버전을 사용하고 있습니까? – VanCowboy

답변

0

시트를 엑셀.

은 열 중복을 제거 컬럼의 단부 1.

  • 할 열 (2, 3)를 복사
  • 을 끝을 나타 내기 위해 행을 추가 제가
    • 짓 수작업를 기록함으로써 생성 된 a 열
    • 다음 수동으로 다시 3 열을 생성합니다. 추가 된 컬럼 노트의 끝을 기준으로합니다.

    .

    Range("A1").Select 
    Selection.End(xlDown).Select 
    Selection.End(xlDown).Select 
    Selection.End(xlUp).Select 
    Range("A12").Select 
    ActiveCell.FormulaR1C1 = "1----" 
    Range("B12").Select 
    ActiveCell.FormulaR1C1 = "2----" 
    Range("C12").Select 
    ActiveCell.FormulaR1C1 = "3----" 
    Range("B1").Select 
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select 
    Selection.Cut 
    Selection.End(xlToLeft).Select 
    Selection.End(xlDown).Select 
    Selection.End(xlDown).Select 
    Range("A13").Select 
    ActiveSheet.Paste 
    Range("B13").Select 
    Range(Selection, Selection.End(xlDown)).Select 
    Range(Selection, Selection.End(xlDown)).Select 
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select 
    Selection.Cut 
    Range("A13").Select 
    Selection.End(xlDown).Select 
    Selection.End(xlDown).Select 
    Selection.End(xlDown).Select 
    Range("A25").Select 
    ActiveSheet.Paste 
    Columns("A:A").Select 
    ActiveSheet.Range("$A$1:$A$46").RemoveDuplicates Columns:=1, Header:=xlNo 
    Range("A13:A22").Select 
    Selection.Cut 
    Range("B1").Select 
    ActiveSheet.Paste 
    Range("A23").Select 
    Range(Selection, Selection.End(xlDown)).Select 
    Selection.Cut 
    Range("C1").Select 
    ActiveSheet.Paste 
    Range("B13").Select 
    

    이제는 행 데이터가 적합하지 않다고 가정합니다. 그것은 ... 작동하지 않습니다. Excel에서 중복을 삭제합니다.

  • 0

    당신은 이보다 더 우아한 방법이있을 것입니다. 원칙적으로 값이 배열에없는 경우 난 그냥 확인 후 배열에 각 값을 넣어 :

    Sub del_values() 
    Dim last_row, last_col, size, y As Integer 
    Dim arr() As Variant 
    
    'finding the last row and last column and calculating the possible size of the array 
    
    last_row = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row 
    last_col = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Column 
    size = last_row * last_col 
    y = 0 
    
    'adjusting the array-size  
    ReDim arr(size) 
    
    For Each cell In ActiveSheet.Range(Cells(1, 1), Cells(last_row, last_col)) 
    
    'avoiding blank cells 
    If cell.Value > "" Then 
    
    'checking if value is already in the array - if not, add it to the array and increase y - if it is, clear the contents of the cell 
    If IsError(Application.Match(cell.Value, arr, 0)) Then 
    arr(y) = cell.Value 
    y = y + 1 
    Else 
    Cells(cell.Row, cell.Column).ClearContents 
    End If 
    End If 
    Next 
    End Sub 
    

    난 당신이 중복을 포함하는 세포와하고 싶었던 확실하지, 그래서 난 그냥 내용을 삭제 물론 당신이 그것을 직접 사용하려는 경우

    Cells(cell.Row, cell.Column).delete 
    

    으로 삭제할 수 있습니다. y는 고유 값의 수와 같습니다.

    관련 문제