PC Review


Reply
Thread Tools Rate Thread

clear contents on linked sheet

 
 
Joanne
Guest
Posts: n/a
 
      7th Jan 2008
WinXP Pro MSOffice 2003

I am trying to use the following procedure to clear both worksheets so
they are ready to produce a fresh report.

These worksheets are linked together on one column, so I need to clear
Sheet3 first to break the links so that I can clear Sheet1.

The second part of the procedure clears sheet1 just fine except it can't
clear the linked col because data is still in that col on sheet3.
The problem is when I step into the procedure and go thru the first part
which is to clear sheet3, it gives me an error (application-defined or
object-defined error) on the 'cells.select' line and stops. I recorded a
macro to get the code for selecting the entire sheet, and 'cells.select'
is what recorded.

Clearly I am missing something here, but I haven't a clue what it might
be.
Could someone please give me a nudge?
BTW, this procedure is a macro applied to a button on sheet1

Public Sub Clear()
' Clear Worksheet values for next report

Sheet3.Activate
Cells.Select
Selection.ClearContents

Sheet1.Activate
Sheets("Sheet1").Select
Rows("15:65").Select
Range("A65").Activate
Selection.SpecialCells(xlCellTypeConstants).Select
Selection.ClearContents
End Sub

Thank you
Joanne
 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      7th Jan 2008
Try this from anywhere in the workbook withOUT selections.
Sub clearshts()
sheet1.usedrange.clearcontents
sheet3.Rows("15:65").SpecialCells(xlCellTypeConstants).ClearContents
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Joanne" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> WinXP Pro MSOffice 2003
>
> I am trying to use the following procedure to clear both worksheets so
> they are ready to produce a fresh report.
>
> These worksheets are linked together on one column, so I need to clear
> Sheet3 first to break the links so that I can clear Sheet1.
>
> The second part of the procedure clears sheet1 just fine except it can't
> clear the linked col because data is still in that col on sheet3.
> The problem is when I step into the procedure and go thru the first part
> which is to clear sheet3, it gives me an error (application-defined or
> object-defined error) on the 'cells.select' line and stops. I recorded a
> macro to get the code for selecting the entire sheet, and 'cells.select'
> is what recorded.
>
> Clearly I am missing something here, but I haven't a clue what it might
> be.
> Could someone please give me a nudge?
> BTW, this procedure is a macro applied to a button on sheet1
>
> Public Sub Clear()
> ' Clear Worksheet values for next report
>
> Sheet3.Activate
> Cells.Select
> Selection.ClearContents
>
> Sheet1.Activate
> Sheets("Sheet1").Select
> Rows("15:65").Select
> Range("A65").Activate
> Selection.SpecialCells(xlCellTypeConstants).Select
> Selection.ClearContents
> End Sub
>
> Thank you
> Joanne


 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      7th Jan 2008
should have been
sheet3.usedrange.clearcontents
sheet1.Rows("15:65").SpecialCells(xlCellTypeConstants).ClearContents

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Don Guillett" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Try this from anywhere in the workbook withOUT selections.
> Sub clearshts()
> sheet1.usedrange.clearcontents
> sheet3.Rows("15:65").SpecialCells(xlCellTypeConstants).ClearContents
> End Sub
>
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "Joanne" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> WinXP Pro MSOffice 2003
>>
>> I am trying to use the following procedure to clear both worksheets so
>> they are ready to produce a fresh report.
>>
>> These worksheets are linked together on one column, so I need to clear
>> Sheet3 first to break the links so that I can clear Sheet1.
>>
>> The second part of the procedure clears sheet1 just fine except it can't
>> clear the linked col because data is still in that col on sheet3.
>> The problem is when I step into the procedure and go thru the first part
>> which is to clear sheet3, it gives me an error (application-defined or
>> object-defined error) on the 'cells.select' line and stops. I recorded a
>> macro to get the code for selecting the entire sheet, and 'cells.select'
>> is what recorded.
>>
>> Clearly I am missing something here, but I haven't a clue what it might
>> be.
>> Could someone please give me a nudge?
>> BTW, this procedure is a macro applied to a button on sheet1
>>
>> Public Sub Clear()
>> ' Clear Worksheet values for next report
>>
>> Sheet3.Activate
>> Cells.Select
>> Selection.ClearContents
>>
>> Sheet1.Activate
>> Sheets("Sheet1").Select
>> Rows("15:65").Select
>> Range("A65").Activate
>> Selection.SpecialCells(xlCellTypeConstants).Select
>> Selection.ClearContents
>> End Sub
>>
>> Thank you
>> Joanne

>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clear contents of last two rows of data on sheet Danielle Microsoft Excel Programming 6 12th Mar 2010 08:29 PM
Copy Sheet to new Sheet and clear cells on original sheets Boiler-Todd Microsoft Excel Misc 7 23rd Sep 2009 10:02 PM
Macro to clear range contents when cell contents are changed by us =?Utf-8?B?U3RldmUgRQ==?= Microsoft Excel Programming 12 22nd Feb 2007 09:09 PM
Macro to Clear Cell Contents based on Cell Value in another Sheet CH Microsoft Excel Discussion 4 26th Jan 2007 08:37 PM
Do not select sheet and clear contents of copied cells Chris Akens Microsoft Excel Programming 3 9th Mar 2004 04:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:30 PM.