[英]Copy data from one cell to another if condition met VBA
我被困在這個相當基本的問題上,盡管試圖通過谷歌搜索來解決它。 如果滿足 InStr 參數中的條件,我需要將數據從 CELL C 復制到 CELL A。 條件是列 C 中的單元格為字母 V。
樣品表:Excel
- Component(A) Description(B) Duplicate(C)
- V806700.B01 Part 1 V806700.B12
- V806700.B02 Part 2 V806700.B13
- V806700.B03 Part 3 NA
- V806700.B04 Part 4 NA
- V806700.B05 Part 5 V806700.B55
- V806700.B06 Part 6 NA
代碼:
`````
Sub copythecell()
Dim cell As Range
For Each cell In Range("C2:C7")
If InStr(cell.Value, "V") > 0 Then
cell.Offset(0, -2).Copy
ActiveCell.Paste
End If
Next cell
End Sub
Sub copythecell()
Dim cell As Range, v
For Each cell In Range("A2:A7").Cells
v = cell.Offset(0, 2).Value
If v Like "V*" Then cell.Value = v
Next cell
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.