Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 插入复制的单元格,然后使用替换函数引用回原始单元格_String_Replace_Insert_Offset - Fatal编程技术网

String 插入复制的单元格,然后使用替换函数引用回原始单元格

String 插入复制的单元格,然后使用替换函数引用回原始单元格,string,replace,insert,offset,String,Replace,Insert,Offset,我目前正在尝试编写一个宏,它基本上取一列,将其复制到右侧,然后更改某些引用以引用上一列 我使用的是replace方法,但是因为我在寻找基于列字母和“2”的特定字符串,所以我使用了一个对象将列字母和“2”组合在一起。更好的解释方法是复制列B并插入,然后在列C中复制 现在我想在公式中找到“C2”和“C3”,并将它们改为“B2”和“B3” 我想这可以通过使用replace方法找到前面提到的字符串并用-1进行偏移来实现。这已经被证明是相当困难的。有什么想法吗 'duplicates column ove

我目前正在尝试编写一个宏,它基本上取一列,将其复制到右侧,然后更改某些引用以引用上一列

我使用的是replace方法,但是因为我在寻找基于列字母和“2”的特定字符串,所以我使用了一个对象将列字母和“2”组合在一起。更好的解释方法是复制列B并插入,然后在列C中复制

现在我想在公式中找到“C2”和“C3”,并将它们改为“B2”和“B3”

我想这可以通过使用replace方法找到前面提到的字符串并用-1进行偏移来实现。这已经被证明是相当困难的。有什么想法吗

'duplicates column over 1'

ActiveCell.EntireColumn.Select
Selection.Copy
ActiveCell.Offset(0, 1).EntireColumn.Select
Selection.Insert Shift:=xlToRight
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone
Application.CutCopyMode = False

'Declarations and Instantiations'
Dim rngo As Range, cell As Range, ranger As Range
Dim lookfor As String
Dim UsedRng As Range, LastRow As Long
Set rngo = Selection.EntireColumn
Set UsedRng = ActiveSheet.UsedRange
LastRow = UsedRng(UsedRng.Cells.Count).Row

rngo.Select

Do Until ActiveCell.Row = LastRow + 1

For Each cell In rngo

Col = SPLIT(ActiveCell(1).Address(1, 0), "$")(0) 'returns just the cell letter'

lookfor = (Col & "2") 'combines the column letter with the number(I BELIEVE THIS IS THE SOURCE OF THE ISSUE BUT IM NOT SURE IN WHAT WAY'

'starts to search the new column for "lookfor" which is just the designated string'
rngo.Replace _What:=lookfor, Replacement:="'offset lookfor by 1 column'",_SearchOrder:=xlByRows, MatchCase:=True

Next cell
ActiveCell.Offset(1, 0).Select
Loop

MsgBox ColumnName(Selection)
MsgBox lookfor

End Sub
已解决:将“rngo.Replace”更改为“ActiveCell.Replace”

已解决:将“rngo.Replace”更改为“ActiveCell.Replace”