Ошибка Excel 13 VBA несоответствие типов для столбцов макроса - PullRequest
1 голос
/ 08 октября 2019

Я пытался запустить этот код для продвижения определенных столбцов

Лист1

enter image description here

Лист2

enter image description here

Но мой код всегда выдает одну и ту же 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
...