Clearing old data from a sheet

  • Thread starter Thread starter 5lmustang
  • Start date Start date
5

5lmustang

Hi

I need to clear all data that may be on a sheet except for the firs
two rows. I have tried to use:

EXCEL::_WORKSHEETPTR OBJSHEET;
....
EXCEL::RANGEPTR RANGE = NULL;

RANGE = OBJSHEET->GETUSEDRANGE();

LONG LROW = (RANGE->GETEND(XLDOWN))->GETROW();
LONG LCOL = (RANGE->GETEND(XLTORIGHT))->GETCOLUMN()

to get the extents of the used range but in some instances GetRow(
returns 65536 which causes my code to puke.

Anyone have a better way of doing this? Is there any useful (thi
automatically excludes MSDN) information out there on this sort o
thing?

Thank
 
5lmustang

To keep your code simple you could use

Rows("2:" & Rows.Count).ClearContents

or

Rows("2:" & Rows.Count).delete



To get last used row and column try

GetBottomRow = TheSheet.Cells.Find(What:="*", SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row

LastColumn = TheSheet.Cells.Find(What:="*", SearchOrder:=xlByColumns
_
SearchDirection:=xlPrevious).Column


To reset the last used row and column that excel thinks is used to wha
is actually used try

Sub ResetLastRow_n_Column()
Dim i As Integer
i = ActiveSheet.UsedRange.Offset(X).Resize(1).Row - 1
i = ActiveSheet.UsedRange.Offset(X).Resize(1).Column - 1
End Su
 

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

Back
Top