[英]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.