excel - 当单元格值为某个文本时复制和粘贴
问题描述
如果 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
祝你有美好的一天 :)
推荐阅读
- sharepoint-online - 在客户端的 PnP 分类选择器控件中设置值
- sql - 复杂的分组案例 - 在组之间使用“分隔 tinyint 标志”
- powerbi - 获取每行的 MAX 列并显示
- javascript - 没有输入字段时如何捕捉键位?
- laravel - 在 laravel 中执行 whereBetween 时一无所获
- sql-server - 我们如何通过正则表达式或 asp.net 中的任何其他方式防止 SQL 注入
- xaml - xamarin 导航栏不显示 TitleView
- outlook - 在 Outlook 的新项目旁边显示 Outlook 加载项
- spring - Spring boot 和 Spring Security,不同的登录表单使用不同的成功处理程序
- python - 计算采样频率的变化