使用VBA在包含特定关键字的任何行之后添加一行并用数据填充列
我需要在包含关键字“skimmer”的任何行之后添加一行,然后使用以下数据填充列:
A 列和 B 列:与上一行中此列中的数据匹配。
D、F、H、I、J、K 列带有文本(这些总是相同的)
这是我到目前为止所拥有的,这不是添加行,似乎代码无法识别 Excel 中的关键字,甚至知道文字在那里..
Sub Skimmer()
Set rng2 = Range("A1").CurrentRegion
lr4 = rng2.Cells(Rows.Count, "K").End(3).Row
For i = lr4 To 2 Step -1
If rng2.Cells(i, 11) Like "*Skimmer*" Then
rng2.Cells(i, 11).Offset(1).EntireRow.Insert
rng2.Cells(i, 3).Offset(1).Resize(1, 9).Value = _
Array("", "ColD", "", "ColF", "", "ColH", "ColI", "ColJ", "ColK")
rng2.Cells(i, 1).Offset(1).Resize(1, 2).Value = rng2.Cells(i, 1).Resize(1, 2).Value
End If
Next i
End Sub
I need to add a row after any row that contains the keyword "skimmer", then fill columns with the following data:
columns A and B: match the data in this column from the row above.
columns D, F, H, I, J, K with text (these will always be the same)
here is what I have so far, this is not adding rows, it seems the code is not recognizing the keyword in the excel, even know the text is there..
Sub Skimmer()
Set rng2 = Range("A1").CurrentRegion
lr4 = rng2.Cells(Rows.Count, "K").End(3).Row
For i = lr4 To 2 Step -1
If rng2.Cells(i, 11) Like "*Skimmer*" Then
rng2.Cells(i, 11).Offset(1).EntireRow.Insert
rng2.Cells(i, 3).Offset(1).Resize(1, 9).Value = _
Array("", "ColD", "", "ColF", "", "ColH", "ColI", "ColJ", "ColK")
rng2.Cells(i, 1).Offset(1).Resize(1, 2).Value = rng2.Cells(i, 1).Resize(1, 2).Value
End If
Next i
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
插入范围行并填充数据
紧凑
论证
Insert Range Rows and Fill With Data
Compact
Argumented