Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Runtime error 1004

Hello,
I have a macro that imports a text file. There is something in the text
file that is throwing error 1004 and I am not sure exactly what it is.
The code is:
Sub terr_100()
ChDir "\\dynamics\Documents\Terry\EOD_REPORTS"
Workbooks.OpenText Filename:= _
"\\dynamics\Documents\Terry\EOD_REPORTS\100_daily_ ar.txt",
Origin:=437, StartRow _
:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1),
Array(14, 1), Array _
(51, 1), Array(65, 1), Array(78, 1), Array(91, 1), Array(104,
1), Array(117, 1)), _
TrailingMinusNumbers:=True
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Windows("100_daily_ar.txt").Activate
Sheets("100_daily_ar").Select
Sheets("100_daily_ar").Move after:=Workbooks("all
a.r.xls").Sheets(1)
Selection.EntireRow.SpecialCells(xlBlanks).EntireR ow.Delete
End Sub
The row that is causing the error is:
Selection.EntireRow.SpecialCells(xlBlanks).EntireR ow.Delete
The error that I get is Run-Time error 1004, cannot use that command on
overlapping selections. I do not see where I am overlapping any
sections. Can anyone help with this? Thanks Terry

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Runtime error 1004

Select A1 and then hold Ctrl down and click on C1. If you then run code
like this:

Selection.EntireRow.Delete

you get your run time error about an overlapping selection. The overlap is
the entire row of A1 and the entire row of C1. They are the same row.

As far as I can tell, what you are trying to do is delete any row that has
at least one empty cell. You can't do it your way unfortunately. Here is
an way that should work. It depends on the entire block being selected when
it is run.

Sub DelAnyRowWithABlankInSelection()
Dim NewRg As Range
Dim CurrRow As Range
Dim BlankCells As Range
On Error GoTo NoBlanks
For Each CurrRow In Selection.Rows
Set BlankCells = CurrRow.SpecialCells(xlCellTypeBlanks)
If NewRg Is Nothing Then
Set NewRg = CurrRow
Else
Set NewRg = Union(NewRg, CurrRow)
End If
Nextrow:
Next
If Not NewRg Is Nothing Then NewRg.Delete (xlShiftUp)
Exit Sub
NoBlanks:
Resume Nextrow
End Sub


--
Jim
"Terry K" wrote in message
oups.com...
| Hello,
| I have a macro that imports a text file. There is something in the text
| file that is throwing error 1004 and I am not sure exactly what it is.
| The code is:
| Sub terr_100()
| ChDir "\\dynamics\Documents\Terry\EOD_REPORTS"
| Workbooks.OpenText Filename:= _
| "\\dynamics\Documents\Terry\EOD_REPORTS\100_daily_ ar.txt",
| Origin:=437, StartRow _
| :=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1),
| Array(14, 1), Array _
| (51, 1), Array(65, 1), Array(78, 1), Array(91, 1), Array(104,
| 1), Array(117, 1)), _
| TrailingMinusNumbers:=True
| Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
| Windows("100_daily_ar.txt").Activate
| Sheets("100_daily_ar").Select
| Sheets("100_daily_ar").Move after:=Workbooks("all
| a.r.xls").Sheets(1)
| Selection.EntireRow.SpecialCells(xlBlanks).EntireR ow.Delete
| End Sub
| The row that is causing the error is:
| Selection.EntireRow.SpecialCells(xlBlanks).EntireR ow.Delete
| The error that I get is Run-Time error 1004, cannot use that command on
| overlapping selections. I do not see where I am overlapping any
| sections. Can anyone help with this? Thanks Terry
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Runtime error 1004

Thank you very much Jim. Problem solved.
Terry

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime error 1004 JR Excel Discussion (Misc queries) 2 November 21st 08 08:29 PM
runtime error 1004 valdesd Excel Discussion (Misc queries) 2 October 12th 05 03:20 PM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
Runtime error 1004 edreczk Excel Programming 1 November 4th 04 10:19 PM
runtime error 1004 monika Excel Programming 3 February 11th 04 09:48 AM


All times are GMT +1. The time now is 11:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"