簡體   English   中英

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

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

我有以下情形:我有兩個工作表RAW和BOM。 我想做的是從RAW中為某些組件填充BOM表。

例如在BOM表中,我有VXL5-50(以黃色突出顯示)。 因此,對於該組件,我搜索sheet1->“連接器類型”列,並查看該字符串是否存在。 如果是這樣,那么我在BOM工作表的“數量”列中增加1。

這是兩張原始和物料清單

http://i43.tinypic.com/aos0uu.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

在此處輸入圖片說明

在此處輸入圖片說明

您可以修改上面的代碼並用於其他條件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM