EXCEL VBA 2차원 테이블을 1차원 테이블로 변환

EXCEL VBA 2차원 테이블을 1차원 테이블로 변환
Sub  2_Click()

    Rem  
    
    Worksheets(1).Activate
    Dim sizeArr(5)
    sizeArr(0) = "XS"
    sizeArr(1) = "S"
    sizeArr(2) = "M"
    sizeArr(3) = "L"
    sizeArr(4) = "XL"
    
    
    Dim col, row, productNum, refCol, targetRow
    
    targetRow = 1
    
    Sheet2.Range("A1:A65536").Clear
    
    Dim iA As Integer
    
    
    Rem  
    For row = 3 To 65536: Rem  
    
        If StrComp(Sheet1.Cells(row, 1), "") = 0 Then GoTo line: Rem  
        
        iA = Asc(Left(Sheet1.Cells(row, 1), 1))
        Rem  , 
        If (iA >= 65 And iA <= 90) Or (iA >= 97 And iA <= 122) Then
        
            For col = 3 To 7: Rem  
                productNum = Sheet1.Cells(row, 1) & Left(Sheet1.Cells(row, 2), 2)
                       
                Rem  
                If StrComp(Left(productNum, 1), "K") = 0 Then
                    refCol = 4
                ElseIf StrComp(Left(productNum, 1), "B") = 0 Then
                    refCol = 3
                ElseIf StrComp(Left(productNum, 1), "C") = 0 Then
                    refCol = 3
                Else
                    refCol = 2
                End If
               
                productNum = productNum & Sheet3.Cells(col - 1, refCol)
                
                Rem  , <=0, , 
                If Sheet1.Cells(row, col) > 0 Then
                    Sheet2.Cells(targetRow, 1) = productNum & "," & Sheet1.Cells(row, col)
                    targetRow = targetRow + 1
                End If
                
            Next
         End If
line:
    Next
    If targetRow = 1 Then
        Worksheets(1).Activate
        MsgBox " !"
    Else
        Sheet2.Range("D4").Value = targetRow - 1
        Worksheets(2).Activate
        MsgBox " !"
    End If
    
End Sub

좋은 웹페이지 즐겨찾기