簡體   English   中英

查找其中包含特定字符串的單元格並將右側的單元格 2 列替換為特定值

[英]Finding a cell with a specific string in it and replacing the cell 2 columns to the right with a specific value

如標題所述,我需要在工作表中找到所有包含特定字符串的單元格,並將右側的單元格 2 列替換為特定值

編輯:這是我到目前為止所擁有的,但不知道 go 從這里到哪里

Sub t()
Dim searchCell As Range  
Dim replaceCell As Range
With Sheets("Chainwire")
    Set searchCell = .Cells.Find(what:="UFFT50")
    Set replaceCell = searchCell.Offset(0, 2)
End With
End Sub

任何幫助深表感謝

嘗試這個:

Sub ReplaceItems()
    Dim col, c, dest As Range
    
    Set col = FindAll(Sheets("Chainwire").UsedRange, "UFFT50") 'get all matches
    
    'loop matches and replace value 2 cells over
    For Each c In col
        c.Offset(0, 2).Value = "a specific value"
    Next
End Sub


'search a Range for `val` and return all matches as a Collection
'   of cells
Public Function FindAll(rng As Range, val As String) As Collection
    Dim rv As New Collection, f As Range
    Dim addr As String
    'adjust Find() arguments to suit your need...
    Set f = rng.Find(what:=val, after:=rng.Cells(rng.Cells.CountLarge), _
        LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, MatchCase:=True)
    If Not f Is Nothing Then addr = f.Address() 'remember first cell found

    Do Until f Is Nothing
        rv.Add f
        Set f = rng.FindNext(after:=f)
        If f.Address() = addr Then Exit Do 'exit if we looped back to the first hit
    Loop

    Set FindAll = rv
End Function

暫無
暫無

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

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