Forum Discussion

hrh_dash's avatar
hrh_dash
Iron Contributor
Aug 11, 2022
Solved

Error pop up: compile error sub or function not definedwhen executing macro

Pop out error: Run time error 13 Type Mismatch when executing macro.   Error was displayed at this line of code below: Set successrng = Find(What:="Success", After:=ActiveCell, LookIn:=xlValues _ ...
  • HansVogelaar's avatar
    HansVogelaar
    Aug 12, 2022

    hrh_dash 

    Try this:

    Sub daily_installment()
        Dim ws           As Worksheet
        Dim lastRow      As Long
        Dim i            As Long
        Dim successrange As Range
        For Each ws In Worksheets
            ws.Rows("1").EntireRow.Delete
            ws.Columns("A:A").TextToColumns Destination:=ws.Range("A1"), DataType:=xlDelimited, _
                                            TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
                                            Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar:=";"
            lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
            ws.Rows(lastRow).EntireRow.Delete
            ws.Range("H:H").EntireColumn.Insert
            ws.Range("H1").Value = "TOTALPAYMENTS"
            Set successrange = ws.Cells.Find(What:="Success", LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False)
            Do While Not successrange Is Nothing
                successrange.EntireColumn.Delete
                Set successrange = ws.Cells.Find(What:="Success", LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False)
            Loop
            lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).EntireRow.Row
            With ws.Range("H2:H" & lastRow)
                .Formula = "=F2*G2"
                .Value = .Value
            End With
            ws.Range("A1").CurrentRegion.EntireColumn.AutoFit
        Next ws
    End Sub

Resources