[英]populate sheet A from sheet B - excel VBA
我有以下情形:我有两个工作表RAW和BOM。 我想做的是从RAW中为某些组件填充BOM表。
例如在BOM表中,我有VXL5-50(以黄色突出显示)。 因此,对于该组件,我搜索sheet1->“连接器类型”列,并查看该字符串是否存在。 如果是这样,那么我在BOM工作表的“数量”列中增加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
您可以修改上面的代码并用于其他条件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.