Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing data in Excel

Status
Not open for further replies.

DKL01

Programmer
Sep 14, 2000
233
US
Hi,

I have navigation bar in my excel. Based on the selection the macro connects to database, retrieves and displays the data below the navigation bar ( from row # 10 ). User can change the criteria and submit for new data.

I was wondering how the clear the previous data (including content and formatting but without clearing the navigation bar in rows 1 thru 10 ) using macro prior to redisplaying data. I know the starting point (Row # 10) but end point is dynamic.

I really appreciate any suggestions.

Thanks
 
Hi,

Here's a way...
Code:
Sub ClearDataArea()
    Dim lLastRow As Long, iLastCol As Integer
        
    With ActiveSheet.UsedRange
        lLastRow = .Row + .Rows.Count - 1
        iLastCol = .Column + .Columns.Count - 1
    End With
    
    Range(Cells(10, 1), Cells(lLastRow, iLastCol)).ClearContents
End Sub
Hope this helps :) Skip,
metzgsk@voughtaircraft.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top