Adding a Row in a table cause an error

dikken20

Board Regular
Joined
Feb 25, 2009
Messages
130
Office Version
  1. 2010
Platform
  1. Windows
Hello,

Why do I get an error on this part (located inside the IF block below) :
VBA Code:
   Cells(RowCnt, 2).EntireRow.Insert = True



VBA Code:
Sub Adding_ROW()
Application.ScreenUpdating = False
    BeginRow = 2
    EndRow = 600
    Inst_Name = Application.InputBox("Enter an Instrument Name")
'   Inst_Serial = Application.InputBox("Enter an Instrument Serial")


    For RowCnt = BeginRow To EndRow
        If Cells(RowCnt, 2).Value > Inst_Name Then
            Cells(RowCnt, 2).EntireRow.Insert = True
                     
        End If
    Next RowCnt
  
End Sub
 
Do you have cell B1048576 accidentally filled?
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
There is an other problem. How to add a item after the last row.
VBA Code:
Sub Adding_ROW()
    Application.ScreenUpdating = False
    Dim BeginRow As Long
    Dim EndRow As Long
    Dim RowCnt As Long
    Dim Inst_Name As String
    BeginRow = 2
    EndRow = Cells(Rows.Count, 2).End(xlUp).Row
    Inst_Name = Application.InputBox("Enter an Instrument Name")
    For RowCnt = BeginRow To EndRow
        If Cells(RowCnt, 2).Value > Inst_Name Then
            Cells(RowCnt, 2).EntireRow.Insert
            Cells(RowCnt, 2) = Inst_Name
            RowCnt = EndRow
        ElseIf RowCnt = EndRow Then
            Cells(RowCnt + 1, 2) = Inst_Name
        End If
    Next RowCnt
    Application.ScreenUpdating = True
End Sub

So far looks good, Thank you!
 
Upvote 0

Forum statistics

Threads
1,215,284
Messages
6,124,059
Members
449,139
Latest member
sramesh1024

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