[英]Find a specific String in a range and copy it to another field in VBA
So I want to find a specific string in a range, get its address and copy its value into a new cell, which depends on the old address 所以我想在范围内找到一个特定的字符串,获取其地址并将其值复制到一个新的单元格中,这取决于旧地址
Here is what I've tried until now: 到目前为止,我一直在尝试以下方法:
Dim c As Range
For Each c In Range("F1:F1500")
If InStr(1, c.Text, "Overall Result") Then
Range(c).Select
Selection.Cut
Range(newAddress).Select
ActiveSheet.Paste
End If
Next c
But I'm not sure about how to get the right address of the cell. 但是我不确定如何获取正确的单元地址。 The new cell should be the old address.row and the old address.column+1 新的单元格应该是旧的address.row和旧的address.column + 1
You can use c.Offset(ColumnOffset:=1)
to move one column right outgoing from the range c
. 您可以使用c.Offset(ColumnOffset:=1)
将一列从范围c
向右移出。
Dim c As Range
For Each c In Range("F1:F1500")
If InStr(1, c.Text, "Overall Result") Then
c.Cut Destination:=c.Offset(ColumnOffset:=1)
End If
Next c
Also have a look at How to avoid using Select in Excel VBA which is a bad practice, slows you down and is not very reliable. 还可以看看如何避免在Excel VBA中使用“选择”,这是一种不好的做法,会使您的速度变慢并且不太可靠。
Dim c As Range
For Each c In Range("F1:F1500")
If InStr(1, c.Text, "Overall Result") Then
Range(c.address).offset(0,1).value = c.text
End If
Next c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.