Help with Run-time Errors '1004

QuickLearner

New Member
Joined
Jun 7, 2011
Messages
3
I have two run-time errors that I'm having an issues with.
1. Run-time error '1004 - Cannot use that command on overlapping selections:

I think this is the code that is giving me a problem:

'(11)Eliminating blank rows
Range("B:B, C:C").Select
X = Selection.SpecialCells(xlCellTypeBlanks).Count
If X <> 0 Then
Range("B:B, C:C").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete
End If

2. Run-time error '1004 - too few parameters expected1. This one shows up when one of the fields on the import file can't be found. I was looking for some error trapping code to fix this one.

Sub ImportBaseFile()
'(1) Open UploadEntries Tab
Sheets("UploadEntries").Select
Range("A1").Select
'Import Company(Division C), Cost Center(Loc C), and Expense Amount(Rpt Exp A) from RS_BaseFile on C:Temp

With ActiveSheet.QueryTables.Add(Connection:=Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=C:\temp\RS_BaseFile.xls;Mode=Share Deny Write;Extended Pr" _
, _
"operties=""HDR=YES;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type" _
, _
"=35;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Dat" _
, _
"abase Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact" _
, "=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False"), _
Destination:=Sheets("UploadEntries").Range("A1"))
.CommandType = xlCmdTable
.CommandText = Array( _
"SELECT `RSA$`.`Division C`, `RSA$`.`Loc C`, `RSA$`.`Rpt Exp A`" & Chr(13) & "" & Chr(10) & "FROM `C:\temp\RS_BaseFile`.`RSA$` `RSA$`" & Chr(13) & "" & Chr(10) & "ORDER BY `RSA$`.`Division C`, `RSA$`.`Loc C`, `RSA$`.`Rpt Exp A`" _
)
.Name = "RS_BaseFile_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = "C:\temp\RS_BaseFile.xls"
.Refresh BackgroundQuery:=False
End With
Call RestrictedStock
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Instead of Range("B:B, C:C").Select, try Columns("B:C").Select.

(It's seldom necessary and never efficient to use Select, but let's get the code working before we try to optimise it.)
 
Upvote 0
Instead of Range("B:B, C:C").Select, try Columns("B:C").Select.

(It's seldom necessary and never efficient to use Select, but let's get the code working before we try to optimise it.)

I tried this and it worked the first time, but when I ran the code again, after I deleted the extra rows in the import file. I got the overlapping error when it got to...Selection.EntireRow.Delete

Columns("B:C").Select
X = Selection.SpecialCells(xlCellTypeBlanks).Count
If X <> 0 Then
Columns("B:C").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete
End If
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,756
Members
452,940
Latest member
rootytrip

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