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 -
 

Some videos you may like

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

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
23,917
If you want everything gone
Code:
ActiveSheet.UsedRange.Clear
If you want to leave the formulas
Code:
ActiveSheet.Cells.SpecialCells(xlCellTypeConstants).Clear
 

Watch MrExcel Video

Forum statistics

Threads
1,123,259
Messages
5,600,575
Members
414,390
Latest member
plimbu

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