当单元格值为某个文本时复制和粘贴
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
祝你有愉快的一天:)
如果 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
祝你有愉快的一天:)