땡큐엑셀vba & 엑셀매크로

실행전

 

실행후

 

'http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=102020101&docId=279521143
'A열에서 같은 이름을 찾아 B열의값으로 채우기

'
'source by 땡큐엑셀vba & 엑셀매크로
'
Sub B열채우기()

    마지막행 = Cells(Cells.Rows.Count, "A").End(xlUp).Row
    
    '
    For i = 1 To 마지막행
    
    
        'B열에 값이 있으면
        B셀값 = Cells(i, "B")
        If B셀값 <> "" Then
            'A열의 값을 기억하고
            A셀값 = Cells(i, "A")
            
             '1.A열 전체에서(검색범위)
             Set 범위 = Range("A:A")
             Set Rng = 범위.Find(what:=A셀값, lookat:=xlWhole)
        
              '검색결과가 있다면
             If Not Rng Is Nothing Then
                strAddr = Rng.Address  '첫 위치 주소
                
                '2.검색결과가 없을때 까지 루프
                Do
                    'Offset메서드를 이용하여 B열에 값을 출력한다.
                    Rng.Offset(0, 1) = B셀값
                    Set Rng = 범위.FindNext(Rng) 'Next
                Loop While Not Rng Is Nothing And Rng.Address <> strAddr
             End If

        End If
        
    
    Next i
    
    
    
    MsgBox "완료되었습니다", vbInformation, "땡큐엑셀vba & 엑셀매크로"


End Sub

 

A열에서 같은값 찾아 B열채우기-find_FindNext-땡큐엑셀vba.xlsm
0.05MB