简体   繁体   English

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

[英]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.

相关问题 VBA 代码查找特定范围内的项目并复制到另一张表 - VBA code to find an item in a specific range and copy to another sheet excel vba-特定的复制/粘贴字符串到另一个工作表,其所有范围都在另一个工作表中的特定范围 - excel vba - specific copy/paste string to another sheet with all its range to specific range in another worksheet 如何使用 VBA 将遵循特定字符串的动态数据范围从一张纸复制到另一张纸? - How do I copy a dynamic range of data that follows a specific string from one sheet to another using VBA? vba excel查找字符串,移动到偏移位置,将动态范围复制到另一个工作表 - vba excel Find string, move to an offset location, copy dynamic range to another sheet VBA 查找特定单词并将值复制到另一个单元格 - VBA to find specific word and copy value to another cell 选择特定字符串后的单元格范围并将其复制到另一个工作表 - Select and copy range of cell after a specific string to another worksheet 复制 - 如果特定范围为空而另一个不是(VBA),则粘贴在行范围上方 - Copy- Paste above row's Range if a specific range is empty and another is not (VBA) 查找并替换VBA中的特定范围 - find and replace for specific range in VBA VBA:复制动态范围直到特定文本 - VBA: Copy dynamic range until a specific text 如何将范围数组复制到VBA中的特定目标? - How to copy Range Array to specific destination in VBA?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM