宏查找值和复制;粘贴到另一个单元格

时间:2013-03-01 04:42:27

标签: excel excel-vba vba

我想创建使用宏的简单工具,如果匹配则必须在D列中找到“R”文本,然后将该单元格值复制并过去到“L”列。

如果为下面的脚本运行宏,我可以得到确切的值,但它已经是一个单元格。所以有人帮我找到整个D列。

D                  L

1111_r             1111_r
0000
22222
348_16re
111
222
333_16re
Dim c As Range
    With ActiveWorkbook.Sheets("PLMSync_NetChange")
        Set c = .Range("D1:D20").Find(What:="_R", _
                                   LookIn:=xlFormulas, LookAt:=xlPart, _
                                   SearchOrder:=xlByRows, _
                                   SearchDirection:=xlNext, MatchCase:=True)
        On Error GoTo NotFoundErr:
            c.Offset(0, 15).Value = c.Value
    End With
    Exit Sub
NotFoundErr:
    Debug.Print "value not found"
End Sub

非常感谢。它现在正在工作......在此过程之后必须将L列值与A cloumn进行比较。 想从L列之前拿_valus并从下面的项目iD单元格到上面的bom更新单元格中找到A列(有限制)。如果匹配则复制并粘贴到M列。

这里我附上了清楚显示的例子。

   A       B       C       D    L           M
BOM Update report for car               
Summary: Additions=14;Removals=10;Changes=3;Same=20             
Add         Remove  Remove
Item Id Revision    ProFeatureID    Item Id 
xxxxxx  0   795 3S2093_L    
xxxxxx  0   802 3S2093_L    
xxxxxx  0   790 3S2093_L    
yyyyyy  0   720 3S2093_L    
yyyyyy  0   817 3S2093_L    
yyyyyy  0   740 3S2093_L    
zzzzzz  0   732 11111_re    11111_re   11111
zzzzzz  0   746 11111_re    11111_re   11111
zzzzzz  0   758 11111_re    11111_re   11111
zzzzzz  0   766 11111_re    11111_re   11111
11111   2   774     
11111   2   777     
11111   2   780     
11111   2   783     
BOM Update report for bike  

3 个答案:

答案 0 :(得分:0)

Dim LvRow As Integer

Dim LvCol As Integer

lastrow = Range("D65354").End(xlUp).Row

LvCol = 4

For LvRow = 1 To lastrow

  If InStr(1, Cells(LvRow, LvCol), "R",vbtextcompare) > 0 Then

      Cells(LvRow, LvCol).Select

      Cells(LvRow, LvCol + 8).Value = Cells(LvRow, LvCol)


 End If

Next

答案 1 :(得分:0)

Sub sample()

    Dim lastRow As Long
    Dim rng As Range

    With Sheets("PLMSync_NetChange")
        .Activate
        lastRow = .Range("D65000").End(xlUp).Row

        For i = 1 To lastRow
            If (InStr(1, .Range("D" & i).Value, "r", vbTextCompare) > 0) Then
                .Range("L" & i).Value = .Range("D" & i).Value
            End If

        Next

    End With

    Exit Sub

NotFoundErr:
    Debug.Print "value not found"
End Sub

答案 2 :(得分:0)

Dim lvrow As Integer

lastrow =范围(“A65354”)。结束(xlUp)。行

对于lvrow = 1到lastrow

If(InStr(1,Cells(lvrow,12),“1”)> 0)然后

If CStr(Mid(Cells(lvrow, 12), 1, InStr(1, Cells(lvrow, 12), "_") - 1) )=CStr(Cells(lvrow, 1)) Then
    Cells(lvrow, 13) = Cells(lvrow, 1)
    Cells(lvrow, 14) = "Match Found"
End If

结束如果

下一步

如果您想要将其他列值粘贴到col M jus中,请更改列号。

相关问题