vb 배운거 써먹을 때가 많네요.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
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 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
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 |