繁体   English   中英

在范围内找到特定的字符串并将其复制到VBA中的另一个字段

[英]Find a specific String in a range and copy it to another field in VBA

所以我想在范围内找到一个特定的字符串,获取其地址并将其值复制到一个新的单元格中,这取决于旧地址

到目前为止,我一直在尝试以下方法:

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

但是我不确定如何获取正确的单元地址。 新的单元格应该是旧的address.row和旧的address.column + 1

您可以使用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

还可以看看如何避免在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM