Я пытался запустить этот код для продвижения определенных столбцов
Лист1
Лист2
Но мой код всегда выдает одну и ту же error 13
ошибку:
Sub TEST_REPLACECOLUMNS_TEST()
Worksheets("Sheet2").Activate
Dim NumofColumns As Long
Dim NumofMoveMortg As Long
Dim NumofMoveOth As Long
Dim AssetNum As Long
Dim FirstColumn As String
Dim StartColumn As String
Dim EndColumn As String
Dim MyRange As String
Dim StartMortg As String
NumofColumns = 3
NumofMoveMort = 15
NumofMoveOth = 1
AssetNum = Worksheets("Sheet1").Range("b3").End(xlToLeft).Row
StartMortg = "C"
FirstColumn = "A"
StartColumn = Chr(Asc("FirstColumn") + NumofColumns * (AssetNum - 1))
EndColumn = Chr(Asc("FirstColumn") + NumofColumns * (AssetNum - 1) + NumofColumns)
Let MyRange = StartColumn & ":" & EndColumn
Columns("myRange").Select
Selection.Replace What:="$A", Replacement:="$" & (Chr(Asc("StartMortg") + NumofMoveMortg * (AssetNum - 1))), LookAt:=xlPart, _
SearchOrder:=xlByColumns, MatchCase:=False
End Sub
новый код после удаления кавычек вокруг переменных, которыеиспользуются в формулах. Я также добавил "LookIn: = xlFormulas"
Sub TEST_REPLACECOLUMNS_TEST ()
Dim NumofColumns As Long
Dim NumofMoveMortg As Long
Dim NumofMoveOth As Long
Dim AssetNum As Long
Dim FirstColumn As String
Dim StartColumn As String
Dim EndColumn As String
Dim MyRange As String
Dim StartMortg As String
NumofColumns = 3
NumofMoveMort = 15
NumofMoveOth = 1
StartMortg = "C"
FirstColumn = "A"
Worksheets("Sheet1").Activate
AssetNum = Worksheets("Sheet1").Range("b3").End(xlToLeft).Row
Worksheets("Sheet2").Activate
StartColumn = Chr(Asc(FirstColumn) + NumofColumns * (AssetNum - 1))
EndColumn = Chr(Asc(FirstColumn) + NumofColumns * (AssetNum - 1) + NumofColumns)
Let MyRange = StartColumn & ":" & EndColumn
Columns(MyRange).Select
Selection.Replace What:="$A", Replacement:="$" & (Chr(Asc(StartMortg) + NumofMoveMort * (AssetNum - 1))), LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByColumns, MatchCase:=False