Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Clearing old data from a sheet


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

--
5lmustan
-----------------------------------------------------------------------
5lmustang's Profile: http://www.excelforum.com/member.php...fo&userid=1548
View this thread: http://www.excelforum.com/showthread.php?threadid=27068

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Clearing old data from a sheet


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

--
mudrake
-----------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...nfo&userid=247
View this thread: http://www.excelforum.com/showthread.php?threadid=27068

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clearing cells without clearing formulas marsjune68 Excel Discussion (Misc queries) 2 April 10th 09 07:39 PM
Clearing Data Troy2006 Excel Discussion (Misc queries) 3 October 31st 08 10:01 PM
clearing data from excell sheet A Excel Discussion (Misc queries) 3 January 28th 08 04:09 PM
VBA Question / Clearing out All Data carl Excel Worksheet Functions 3 March 2nd 05 07:57 PM
macro? clearing/ transferring info to another sheet asm Excel Programming 0 November 24th 03 03:58 AM


All times are GMT +1. The time now is 10:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"