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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
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
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,208
If you want everything gone
Code:
ActiveSheet.UsedRange.Clear
If you want to leave the formulas
Code:
ActiveSheet.Cells.SpecialCells(xlCellTypeConstants).Clear
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,988
Messages
5,834,733
Members
430,315
Latest member
bobh63

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
Top