簡體   English   中英

當單元格值是特定文本時復制並粘貼

[英]Copy and paste when cell value is a certain text

如果G =“ FUTURE”,我正在嘗試將H列中的某些值復制並粘貼到C中。

Dim range1 As range
Dim cell As range
Set range1 = Sheets("Paste Port here - addFutureSDL").range("G:G")

For Each cell In range1
    If cell.Value = "FUTURE" Then

我看到您選擇了整個列“ G”,更好的主意是設置“ G”的最后一行,然后從1迭代到最后一行。


Sub test()

Dim sht As Worksheet
Set sht = ThisWorkbook.Sheets("Paste Port here - addFutureSDL")

Start_row = 1
Dim Last_row As Integer
Last_row = sht.Cells(sht.Rows.Count, "G").End(xlUp).Row 'finding last row (if used whole column "G" - can be deleted
Dim range1 As range
Set range1 = sht.range(Cells(Start_row, 7), Cells(Last_row, 7)) ' here u can change if u need to iterate through whole column "G" just to sht.range("G:G")

For Each cell In range1
    If cell = "FUTURE" Then
        cell.Offset(0, -4) = cell.Offset(0, 1) 'replacing
    End If
Next cell

End Sub

祝你有美好的一天 :)

暫無
暫無

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

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