PC Review


Reply
Thread Tools Rate Thread

clearcontents problem

 
 
=?Utf-8?B?RnJhbms=?=
Guest
Posts: n/a
 
      27th Apr 2007
I am using a commandbutton_click sub on a specific worksheet to automate some
reset features on a timesheet I've built. I want to be able to clear and
reset values on other worksheets in the same workbook at the same time.
Inside the commandbutton1_click sub on "Sheet1" I use the code

Worksheet("Sheet2").Range(cells(rowcounter,
columncounter),cells(rowcounter+2,columncounter +2).clearcontents

where rowcounter and columncounter are locally dimmed integers with verified
values (I can see them in the debug)

However, I get a run time 1004 error when this line executes -- if I change
the range designation above to "A1:C3" format, I don't get the error. Is it
a problem that rowcounter and columncounter are locally defined?

Any help or advice would be appreciated.

Thanks.
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      27th Apr 2007
I'd bet it's because the cells() stuff isn't qualified:

with Worksheet("Sheet2")
.Range(.cells(rowcounter, columncounter), _
.cells(rowcounter+2,columncounter +2)).clearcontents
end with

ps. it's better to copy|paste from the VBE than to retype the code and
introduce other typos. (Like missing a closing paren.)



Frank wrote:
>
> I am using a commandbutton_click sub on a specific worksheet to automate some
> reset features on a timesheet I've built. I want to be able to clear and
> reset values on other worksheets in the same workbook at the same time.
> Inside the commandbutton1_click sub on "Sheet1" I use the code
>
> Worksheet("Sheet2").Range(cells(rowcounter,
> columncounter),cells(rowcounter+2,columncounter +2).clearcontents
>
> where rowcounter and columncounter are locally dimmed integers with verified
> values (I can see them in the debug)
>
> However, I get a run time 1004 error when this line executes -- if I change
> the range designation above to "A1:C3" format, I don't get the error. Is it
> a problem that rowcounter and columncounter are locally defined?
>
> Any help or advice would be appreciated.
>
> Thanks.


--

Dave Peterson
 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      27th Apr 2007

) misssing. I've done this too

--
Don Guillett
SalesAid Software
(E-Mail Removed)
"Frank" <(E-Mail Removed)> wrote in message
news:AD8283DA-0F07-4E5B-901D-(E-Mail Removed)...
>I am using a commandbutton_click sub on a specific worksheet to automate
>some
> reset features on a timesheet I've built. I want to be able to clear and
> reset values on other worksheets in the same workbook at the same time.
> Inside the commandbutton1_click sub on "Sheet1" I use the code
>
> Worksheet("Sheet2").Range(cells(rowcounter,
> columncounter),cells(rowcounter+2,columncounter +2).clearcontents
>
> where rowcounter and columncounter are locally dimmed integers with
> verified
> values (I can see them in the debug)
>
> However, I get a run time 1004 error when this line executes -- if I
> change
> the range designation above to "A1:C3" format, I don't get the error. Is
> it
> a problem that rowcounter and columncounter are locally defined?
>
> Any help or advice would be appreciated.
>
> Thanks.


 
Reply With Quote
 
=?Utf-8?B?RnJhbms=?=
Guest
Posts: n/a
 
      27th Apr 2007
OK, wow, it worked PERFECTLY!!! Magic!! Thanks a ton!!!!!!!

Weird -- how isn't the cells stuff qualifed in the original? It leads off
with the Worksheets designation for the target worksheet?

"Dave Peterson" wrote:

> I'd bet it's because the cells() stuff isn't qualified:
>
> with Worksheet("Sheet2")
> .Range(.cells(rowcounter, columncounter), _
> .cells(rowcounter+2,columncounter +2)).clearcontents
> end with
>
> ps. it's better to copy|paste from the VBE than to retype the code and
> introduce other typos. (Like missing a closing paren.)
>
>
>
> Frank wrote:
> >
> > I am using a commandbutton_click sub on a specific worksheet to automate some
> > reset features on a timesheet I've built. I want to be able to clear and
> > reset values on other worksheets in the same workbook at the same time.
> > Inside the commandbutton1_click sub on "Sheet1" I use the code
> >
> > Worksheet("Sheet2").Range(cells(rowcounter,
> > columncounter),cells(rowcounter+2,columncounter +2).clearcontents
> >
> > where rowcounter and columncounter are locally dimmed integers with verified
> > values (I can see them in the debug)
> >
> > However, I get a run time 1004 error when this line executes -- if I change
> > the range designation above to "A1:C3" format, I don't get the error. Is it
> > a problem that rowcounter and columncounter are locally defined?
> >
> > Any help or advice would be appreciated.
> >
> > Thanks.

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      27th Apr 2007
In your original .range was qualified, but cells weren't:

Worksheet("Sheet2").Range(cells(rowcounter, columncounter), _
cells(rowcounter+2,columncounter +2).clearcontents

You could use:
Worksheet("Sheet2").Range(Worksheet("Sheet2").cells(rowcounter,columncounter), _
Worksheet("Sheet2").cells(rowcounter+2,columncounter +2)).clearcontents

If you were a glutton for punishment, er, typing.

Those unqualified cells() will refer to either the activesheet (in a General
module) or the sheet that owns the code (if the code is in a worksheet module).





Frank wrote:
>
> OK, wow, it worked PERFECTLY!!! Magic!! Thanks a ton!!!!!!!
>
> Weird -- how isn't the cells stuff qualifed in the original? It leads off
> with the Worksheets designation for the target worksheet?
>
> "Dave Peterson" wrote:
>
> > I'd bet it's because the cells() stuff isn't qualified:
> >
> > with Worksheet("Sheet2")
> > .Range(.cells(rowcounter, columncounter), _
> > .cells(rowcounter+2,columncounter +2)).clearcontents
> > end with
> >
> > ps. it's better to copy|paste from the VBE than to retype the code and
> > introduce other typos. (Like missing a closing paren.)
> >
> >
> >
> > Frank wrote:
> > >
> > > I am using a commandbutton_click sub on a specific worksheet to automate some
> > > reset features on a timesheet I've built. I want to be able to clear and
> > > reset values on other worksheets in the same workbook at the same time.
> > > Inside the commandbutton1_click sub on "Sheet1" I use the code
> > >
> > > Worksheet("Sheet2").Range(cells(rowcounter,
> > > columncounter),cells(rowcounter+2,columncounter +2).clearcontents
> > >
> > > where rowcounter and columncounter are locally dimmed integers with verified
> > > values (I can see them in the debug)
> > >
> > > However, I get a run time 1004 error when this line executes -- if I change
> > > the range designation above to "A1:C3" format, I don't get the error. Is it
> > > a problem that rowcounter and columncounter are locally defined?
> > >
> > > Any help or advice would be appreciated.
> > >
> > > Thanks.

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
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
ClearContents =?Utf-8?B?UGF1bCBEZW5uaXM=?= Microsoft Excel Programming 2 11th Sep 2007 02:58 PM
ClearContents not clearing :( JoeH Microsoft Excel Programming 1 27th Sep 2004 02:59 AM
Clearcontents Caroline Vincent Microsoft Excel Programming 2 9th Sep 2004 11:03 AM
Clearcontents K Dales Microsoft Excel Programming 0 27th Feb 2004 01:52 PM
Re: Clearcontents Dick Kusleika Microsoft Excel Programming 0 17th Feb 2004 05:42 PM


Features
 

Advertising
 

Newsgroups
 


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