简体   繁体   English

从工作表B填充工作表A-Excel VBA

[英]populate sheet A from sheet B - excel VBA

I have the following scenario: I have two worksheets RAW and BOM. 我有以下情形:我有两个工作表RAW和BOM。 What I would like to do is populate the BOM sheet FROM the RAW for certain components. 我想做的是从RAW中为某些组件填充BOM表。

For example in BOM worksheet I have VXL5-50 (highlighted in yellow). 例如在BOM表中,我有VXL5-50(以黄色突出显示)。 So for that component, I search sheet1--> 'connector type' column and look if that string exists. 因此,对于该组件,我搜索sheet1->“连接器类型”列,并查看该字符串是否存在。 If it does, then I increment by 1 in the QTY column in the BOM worksheet 如果是这样,那么我在BOM工作表的“数量”列中增加1。

Here are the two sheets RAW AND BOM 这是两张原始和物料清单

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

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

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

在此处输入图片说明

在此处输入图片说明

You can modify the above code and use for other criteria. 您可以修改上面的代码并用于其他条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM