2013-07-15 5 views
0

다음과 같은 시나리오가 있습니다 : 두 개의 워크 시트 RAW 및 BOM이 있습니다. 내가 뭘하고 싶은지 특정 구성 요소에 대한 원시에서 BOM 시트를 채우는 것입니다.시트 B에서 Excel 시트 채우기

예를 들어 BOM 워크 시트에는 VXL5-50 (노란색으로 강조 표시)이 있습니다. 그래서 해당 구성 요소에 대해 sheet1 -> 'connector type'열을 검색하고 해당 문자열이 있는지 살펴 봅니다. 두 장의 RAW 및 BOM

http://i43.tinypic.com/aos0uu.jpg

http://i43.tinypic.com/j5cxg7.jpg

답변

1
Sub test() 

Dim rng As Range 

Dim dblrow As Double 

'shtSearch,shtCoutn are sheet names. 

    lastrow = shtSearch.Cells(Rows.Count, 1).End(xlUp).Row 

    j = 0 

For i = 1 To lastrow 
    If InStr(1, shtSearch.Cells(i, 1), "abcd", vbTextCompare) > 0 Then 
    'Count the search 
     j = j + 1 
    End If 
Next 

Set scrRng = shtCount.Range("A:A") 

Set rng = scrRng.Find(What:="abcd", After:=ActiveCell, LookIn:=xlFormulas, LookAt _ 
     :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _ 
     False, SearchFormat:=False) 

dblrow = Mid(rng.Address, 4, Len(rng.Address) - 3) 

shtCount.Cells(dblrow, 2) = j 

End Sub 

enter image description here

는 않는 경우, 나는 BOM 워크 시트 여기

의 수량 열에서 1 씩 증가된다

enter image description here

위 코드를 수정하여 다른 기준에 사용할 수 있습니다.