Selecting only cells with Data in them

miaamark

New Member
Joined
Dec 1, 2004
Messages
25
Through a Macro in Excel 2003, I was able to select an entire worksheet (all of the cells)and delete all of the data in the worksheet.

When I converted it to Excel 2007, I am no longer able to select the entire worksheet and delete all of the data - I get an error that makes Excel "not responsive". Apparently selecting all of the cells is too much -

Is there a way to select a range starting with A1 and ending with the lowest & furthest right data? The amount of data in the sheet varies widely with selected dates (and no - the furthest right column might not have the largest row number)

Thanks -
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
This will give the last data cell, from here you can define your used range:

Sub myLastData()
Dim LngLstRow&, LngLstCol&

With ActiveSheet.UsedRange
LngLstCol = .Columns.Count + .Column - 1
LngLstRow = .Rows.Count + .Row - 1
End With

MsgBox "The Last Data is in:" & vbLf & vbLf & _
"Column: " & LngLstCol & vbLf & _
Space(6) & "Row: " & LngLstRow & vbLf & vbLf & _
"Address: " & Cells(LngLstRow, LngLstCol).Address
End Sub
 
Upvote 0
If you want everything gone
Code:
ActiveSheet.UsedRange.Clear
If you want to leave the formulas
Code:
ActiveSheet.Cells.SpecialCells(xlCellTypeConstants).Clear
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,557
Latest member
richa mishra

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