Deleting 63,886 Blank Rows Under My Data

K

Kajuliano

I am working on an excel file in which I currently have data in 1,650 rows
and there are blank cells within the rows I am working on that need to stay
blank. My main problem is deleteing the extra 65,536 blank rows below my data
that randomly appeared when I copy and pasted my data to a new workbook. When
I highlight a single blank row or many blank rows beneath my data and hit
delete row, they do not go away and it is really annoying because my scroll
bar had become all but useless- please help! Thanks!
 
K

Kajuliano

Thanks for the website- I tried highlighing the rows and deleting and that
didn't reset the range. I even saved and closed but I have office 2007 so I
don't think that is an issue. They give a macro to programatically reset the
used range but I'm not quite sure how to use the macro-- do I have to put in
values or can I simply compy and paste it without adding or changing
anything? Also, every time I open and close this file, this message pops up :
Compile error in hidden module: DistMon-- think that has anything to do with
it?? Thanks!!
 
K

Kajuliano

Thanks for the reply-- that was the same website FSt1 directed me to as well
and I could not reset the used range using this method for some reason. As I
said in my reply to FSt1 above I am unclear on using the macro to
programatically reset the used range-- any direction in that area would be
helpful thanks!
 
T

T. Valko

I just tried both methods in an Excel 2007 file and both methods worked.

I'm kind of suspicious of this:
 
K

Kajuliano

Well i copied and pasted all of my data into a new workbook just to make sure
I didn't hit some weird setting in the original one and the highlight delete
method still did not work. Then I copied the macro and ran it and it made it
so my scroll bar actually works well now, but the extra rows are still there.
All that I cared about was the scroll bar working so I am satisfied. As for
the DistMon error I think it has something to do with different Adobe files
that are stored on my computer (I just looked this up). Thank you for the
time and the help!!
 
K

Kajuliano

Thanks-- I am actually working from a remote desktop connection through my
university and I do not think we have access to change settings but I'm fine
with this little error message, it doesn't bother me much- thanks though!
 
T

T. Valko

Glad to hear you got it to work (one way or the other!).
I copied the macro and ran it and it made it so my
scroll bar actually works well now, but the extra
rows are still there.

Yeah, as I noted in my other reply you're not actually deleting (removing)
the rows/columns. You're just resetting where Excel thinks your data ends
(the used range). The scroll bar operation correlates to the size of the
used range.
 
R

rory_r

Thanks for this info.I used it too.
However I keep getting an error when I run the same script from the link.
the debugger stops here- with an application-defined or object defined errror.

Else
.Range(.Cells(myLastRow + 1, 1), _
.Cells(.Rows.Count, 1)).EntireRow.Delete
.Range(.Cells(1, myLastCol + 1), _
.Cells(1, .Columns.Count)).EntireColumn.Delete
End If
End With

Any ideas
Rory
 
D

Dave Peterson

I'm guessing that it's the first logical line (first 2 lines of code) that is
causing the trouble.

What does myLastRow equal?

Add
MsgBox MyLastRow
right before this portion of code.

And is there any chance that the worksheet is protected?
 
R

rory_r

I ran the MSG box and it returned 0
After I run the script and get the error (with the option of running the
debugger), the spread sheets extra rows over 600 are gone. So it seems to
work to that point.

As far as protected, it's not, it probably should be tho.
Rory
 
D

Dave Peterson

One of the things that isn't apparent to me is what the .range() and .cells()
refer to.

There's a "with ..." statement that you haven't shared. Maybe it's not what you
think.

If you're using a variable in that with statement, share what it holds, too.
 
R

rory_r

Dave,
FIrstly, thanks so much for your help.
Here's the entire section.

Dim myLastRow As Long
Dim myLastCol As Long
Dim wks As Worksheet
Dim dummyRng As Range


For Each wks In ActiveWorkbook.Worksheets
With wks
myLastRow = 0
myLastCol = 0
Set dummyRng = .UsedRange
On Error Resume Next
myLastRow = _
.Cells.Find("*", after:=.Cells(1), _
LookIn:=xlFormulas, lookat:=xlWhole, _
searchdirection:=xlPrevious, _
searchorder:=xlByRows).Row
myLastCol = _
.Cells.Find("*", after:=.Cells(1), _
LookIn:=xlFormulas, lookat:=xlWhole, _
searchdirection:=xlPrevious, _
searchorder:=xlByColumns).Column
On Error GoTo 0

If myLastRow * myLastCol = 0 Then
.Columns.Delete
Else
.Range(.Cells(myLastRow + 1, 1), _
.Cells(.Rows.Count, 1)).EntireRow.Delete
.Range(.Cells(1, myLastCol + 1), _
.Cells(1, .Columns.Count)).EntireColumn.Delete
End If
End With
Next wks

End Sub
 
D

Dave Peterson

I don't understand how it blows up on the Else portion of this section:
If myLastRow * myLastCol = 0 Then
.Columns.Delete
Else
.Range(.Cells(myLastRow + 1, 1), _
.Cells(.Rows.Count, 1)).EntireRow.Delete
.Range(.Cells(1, myLastCol + 1), _
.Cells(1, .Columns.Count)).EntireColumn.Delete
End If

If myLastRow is really 0, then the "then" portion should be followed. That
means this line:

..columns.delete

should be the line that's running.

I don't have a guess.

rory_r said:
Dave,
FIrstly, thanks so much for your help.
Here's the entire section.

Dim myLastRow As Long
Dim myLastCol As Long
Dim wks As Worksheet
Dim dummyRng As Range

For Each wks In ActiveWorkbook.Worksheets
With wks
myLastRow = 0
myLastCol = 0
Set dummyRng = .UsedRange
On Error Resume Next
myLastRow = _
.Cells.Find("*", after:=.Cells(1), _
LookIn:=xlFormulas, lookat:=xlWhole, _
searchdirection:=xlPrevious, _
searchorder:=xlByRows).Row
myLastCol = _
.Cells.Find("*", after:=.Cells(1), _
LookIn:=xlFormulas, lookat:=xlWhole, _
searchdirection:=xlPrevious, _
searchorder:=xlByColumns).Column
On Error GoTo 0

If myLastRow * myLastCol = 0 Then
.Columns.Delete
Else
.Range(.Cells(myLastRow + 1, 1), _
.Cells(.Rows.Count, 1)).EntireRow.Delete
.Range(.Cells(1, myLastCol + 1), _
.Cells(1, .Columns.Count)).EntireColumn.Delete
End If
End With
Next wks

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top