VBA Help

david.segal

New Member
Joined
Jul 6, 2012
Messages
3
I have recently inherited a spreadsheet at work with various macros included. One of the macros is currently pulling through an error despite it been the same as in a similar file.

I am currently unable to find the reason for the error. Can anyone help?

Thanks



Sub InsertRow()


On Error GoTo errorhandler



strPwd1 = "thames"
Sheets("Listing").Select
ActiveSheet.Unprotect (strPwd1)
Application.ScreenUpdating = False
Range("A6").Select
Selection.End(xlDown).EntireRow.Copy
Selection.End(xlDown).Offset(1, 0).Insert
Selection.End(xlDown).Select
Application.CutCopyMode = False
ActiveCell.Value = "Select..."
ActiveCell.Offset(0, 2).Value = "Select..."
ActiveCell.Offset(0, 3).Value = "Select..."
ActiveCell.Offset(0, 5).Value = "Select..."
ActiveCell.Offset(0, 6).Value = "Select..."
ActiveCell.Offset(0, 7).Value = "Select..."
ActiveCell.Offset(0, 8).Value = "Select..."
ActiveCell.Offset(0, 9).Value = "Select..."
ActiveCell.Offset(0, 10).Value = "Select..."
ActiveCell.Offset(0, 12).Value = "Enter Value..."
ActiveCell.Offset(0, 13).Value = "Select %..."
ActiveCell.Offset(0, 15).Value = ""
Call protectx

Application.ScreenUpdating = True

Exit Sub
errorhandler:

MsgBox ("There is an error - please contact Finance")

Application.ScreenUpdating = True
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Have you contacted Finance ;)

Seriously though take out the line:

Rich (BB code):
On Error GoTo errorhandler


And let us know where the code is breaking and what error you get.

Dom
 
Upvote 0
Unfortunltey I am finance, so have been contacted.</SPAN>

I have removed the error code and the macro falls down at:


Selection.End(xlDown).Offset(1, 0).Insert


When I look at the macro that is working after this line it goes to a different macro outside of the code, but I can't see where the macro is asking it to go there.

Thanks</SPAN>
 
Upvote 0
This means that the selected row after xlDown is the last row in a sheet. Trying to exceed sheet's limits raises error.
 
Upvote 0
Which is the cell selected if you change it to:

Rich (BB code):
Selection.End(xlDown).Select


Dom
 
Upvote 0
I have deleted rows from the bottom of the sheet to the start of the data and file seems to be working as it should now.

Thanks all for your help.

:)
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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