bug on the code

Hansulet

Board Regular
Joined
Jan 24, 2013
Messages
169
Office Version
  1. 2021
Platform
  1. Windows
I have the bellow code:
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A2").Select
ActiveCell.FormulaR1C1 = "Nr decizie"
But I have the bug on the second line.
Could you explain me why?
Please help me to remove the bug
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try this:
(note that you can get rid of the "Selects" - they are not necessary and slow the code down)

VBA Code:
Columns("A:A").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A2").FormulaR1C1 = "Nr decizie"
 
Upvote 0
Now I have bug on your line:
Columns("A:A").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
 
Upvote 0
Did you copy and paste my code, exactly as I have written it (and not tried to type it yourself)?
What is the exact error message you are getting?

Do you have any of the following?
- Merged cells in column A
- Protected cells in column A
- Anything in column XFD
 
Upvote 0
Run-time error '1004':
Microsoft Excel can't insert new cells because it would push non-empty cells off the end of the worksheet. These non-empty cells might appear empty but have blank values, some formatting, or a formula. Delete enough rows or columns to make room for what you want to insert and then try again
 
Upvote 0
Run-time error '1004':
Microsoft Excel can't insert new cells because it would push non-empty cells off the end of the worksheet. These non-empty cells might appear empty but have blank values, some formatting, or a formula. Delete enough rows or columns to make room for what you want to insert and then try again
That tells you that you have done something to the last possible column of Excel ("XFD") that it thinks you are using it.
If you have formatted your entire page, that could cause this to happen.

If you hit CTRL and END at the same time, what cell does your cursor jump to?
This is what Excel thinks is your last used cell on the sheet.

If you do not want to go back and fix your sheet, you could just delete the last column (if you are sure there is nothing of value in it) before inserting a new one, i.e.
VBA Code:
Columns("XFD:XFD").Delete Shift:=xlToLeft
Columns("A:A").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A2").FormulaR1C1 = "Nr decizie"
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,217,391
Messages
6,136,324
Members
450,005
Latest member
BigPaws

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