Excel VBA 활용하기

vb 배운거 써먹을 때가 많네요.

vba01

Sub Select1()
    For i = 1 To 54
   
        Dim sName1 As String
        Dim sName2 As String
        
        sName1 = Trim(Sheet1.Cells(i, 2))
        
        For j = 1 To 96            
            sName2 = Trim(Sheet2.Cells(j, 1))
            '//Debug.Print sName1, sName2
            If ((sName1 = sName2) And (sName1 = sName2)) Then
               Sheet1.Cells(i, 3) = IIf(Sheet2.Cells(j, 2) > 0, Sheet2.Cells(j, 2), "")
               Sheet1.Cells(i, 4) = Sheet2.Cells(j, 3)
               Sheet1.Cells(i, 5) = IIf(Sheet2.Cells(j, 4) > 0, Sheet2.Cells(j, 4), "")
               Sheet1.Cells(i, 6) = Sheet2.Cells(j, 5)
             Exit For
            End If
        Next j
    
    Next i
End Sub

Sub Select1()
Dim price  As Integer
 
    For i = 1 To 13
   
        Dim sName1 As String
        Dim sName2 As String
        
        sName1 = Trim(Sheet1.Cells(i, 1))
        sName2 = Trim(Sheet1.Cells(i, 2))
        
        price = 0 '//초기값
        If (Trim(sName1) = "기타" And Trim(sName2) = "문자2") Then
          price = Sheet1.Cells(i, 3) + price
          Sheet1.Cells(15, 1) = price
        End If
        
     Next i
    
End Sub


샘플 3

Sub Select1()
    
    For i = 2 To 29
   
        Dim s1 As Integer
        
        Dim s2 As Integer
                
        s1 = Trim(Sheet1.Cells(i, 1))
        
        For j = 2 To 4
        
            s2 = Trim(Sheet1.Cells(i, j))
            
            If (s1 <= s2) Then
             s1 = s2
             
             Sheet1.Cells(i, 6 + j) = s2
             
            End If
            
        'Debug.Print s2
        
        Next j
        
        Sheet1.Cells(i, 6) = s1
        
        'Debug.Print s1
        
    Next i
End Sub