从表B填充表A - excel VBA

时间:2013-07-15 04:30:01

标签: excel vba populate

我有以下情况: 我有两个工作表RAW和BOM。我想要做的是从RAW填充某些组件的BOM表。

例如在BOM工作表中,我有VXL5-50(以黄色突出显示)。所以对于那个组件,我搜索sheet1 - > 'connector type'列并查看该字符串是否存在。如果是,那么我在BOM工作表的数量列中增加1

以下是两张RAW AND BOM

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

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

1 个答案:

答案 0 :(得分: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

enter image description here

您可以修改上述代码并用于其他标准。