Excel VBA - Search Range - If Cell Contains Text Then Copy Cell - Paste Offset 2,1
我正在尝试简化我每周使用的 Excel 工作表。
我正在尝试创建一个 VBA 宏来执行以下操作:
任何人都可以给我的任何帮助,我将不胜感激。我搜索了其他宏,并试图修改它们以供我使用,但无济于事。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | **Example Before Macro** A B C D E 1 Hi 2 Test 3 4 Done 5 6 **Example After Macro Has Been Run** A B C D E 1 Hi 2 Test 3 Hi 4 Done Test 5 6 Done |
当前代码:
1 2 3 4 5 6 7 8 9 10 | Sub CopyC() Dim SrchRng As Range, cel As Range Set SrchRng = Range("C1:C10") For Each cel In SrchRng If InStr(1, cel.Value) > 0 Then cel.Offset(2, 1).Value ="-" End If Next cel End Sub |
你很接近:
1 2 3 4 5 6 7 8 9 | Sub CopyC() Dim SrchRng As Range, cel As Range Set SrchRng = Range("C1:C10") For Each cel In SrchRng If cel.Value <>"" Then cel.Offset(2, 1).Value = cel.Value End If Next cel End Sub |
我在 D 列中添加了 1-6 以表明它忽略了空格