Why am I getting an Automation error Here?

prabha_friend

Board Regular
Joined
Jun 28, 2011
Messages
95
Code:
If .UsedRange.Columns.Count > 23 Then .Range(.Columns(24), .UsedRange.Columns(.UsedRange.Columns.Count)).EntireColumn.Delete shift:=xlLeft
If .UsedRange.Columns.Count > 23 Then
    .Name = .Name & "(1)"
    Set varTemp = .Parent.Sheets.Add(After:=.Parent.Sheets(.Name))
    varTemp.Name = Left(.Name, Len(.Name) - 3)
    .Activate   'I think activation is required here
    .Range(Columns(1), Columns(23)).Copy
    varTemp.Columns(1).Insert
    Excel.Application.DisplayAlerts = False
    .Delete
    Excel.Application.DisplayAlerts = True
    Set TempSheet = varTemp
End If
.UsedRange.Columns(1).Cells.SpecialCells(xlCellTypeBlanks).EntireRow.Delete 'Unique Column
I am getting the following error on the last statement of the above quoted codes:

Run-time error '-2147221080 (800401a8)':

Automation error
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi,

You have not shown all your code but my guess would be that it is objecting to you trying to remove rows from a worksheet you have just deleted.

Code:
If .UsedRange.Columns.Count > 23 Then .Range(.Columns(24), .UsedRange.Columns(.UsedRange.Columns.Count)).EntireColumn.Delete shift:=xlLeft
If .UsedRange.Columns.Count > 23 Then
    .Name = .Name & "(1)"
    Set varTemp = .Parent.Sheets.Add(After:=.Parent.Sheets(.Name))
    varTemp.Name = Left(.Name, Len(.Name) - 3)
    .Activate   'I think activation is required here
    .Range(Columns(1), Columns(23)).Copy
    varTemp.Columns(1).Insert
    Excel.Application.DisplayAlerts = False
    [B][COLOR=#ff0000].Delete[/COLOR][/B]
    Excel.Application.DisplayAlerts = True
    Set TempSheet = varTemp
End If
[B][COLOR=#ff0000].UsedRange.Columns(1).Cells.SpecialCells(xlCellTypeBlanks).EntireRow.Delete[/COLOR][/B] 'Unique Column
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,366
Members
449,080
Latest member
Armadillos

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