Run Time Error 13: Type Mismatch

jwb1012

Board Regular
Joined
Oct 17, 2016
Messages
167
Hi, I am receiving a "Run Time Error 13: Type Mismatch" with the following code. Any thoughts? I cant figure out what to do.

On this line:
Ins = Sh.Cells(n, "A").Value


Code:
Sub InsertRows()
Dim End_Row As Long, n As Long, Ins As Long
Dim Sh As Worksheet
For Each Sh In ActiveWorkbook.Sheets
    If Left(Sh.Name, 9) = "Labor BOE" Then
        
        End_Row = Sh.Range("L" & Rows.Count).End(xlUp).Row
        
        Application.ScreenUpdating = False
        For n = End_Row To 3 Step -1
          [U][I][B]  Ins = Sh.Cells(n, "A").Value[/B][/I][/U]
            
            If Ins > 0 Then
                Sh.Range("A" & n + 1 & ":A" & n + Ins).EntireRow.Insert
                Sh.Range("C" & n & ":L" & n).Copy Destination:=Sh.Range("C" & n + 1 & ":L" & n + Ins)
            End If
        Next n
        
    End If
Next Sh
MsgBox "BOE Generation Complete"
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I would guess that some cell contains a text value. Since Ins is dimensioned as Long, it would require a numeric value in that cell. You could either declare Ins as Variant, or use code like this to coerse the value into a Data type Long

Code:
Ins = Int(Val(Cstr(Sh.Cells(n, "A").Value)))
 
Upvote 0

Forum statistics

Threads
1,215,045
Messages
6,122,836
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top