Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default clearcontents problem

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default clearcontents problem

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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default clearcontents problem

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default clearcontents problem

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").cell s(rowcounter,columncounter), _
Worksheet("Sheet2").cells(rowcounter+2,columncount er +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
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
xlUnlockedCells ClearContents Possible ? Corey Excel Programming 3 January 4th 07 03:19 AM
Clearcontents Caroline Vincent Excel Programming 2 September 9th 04 11:03 AM
ClearContents - Except NamedRanges Mike Fogleman Excel Programming 8 September 2nd 04 01:19 AM
Clearcontents K Dales Excel Programming 0 February 27th 04 01:52 PM
Clearcontents Dick Kusleika[_3_] Excel Programming 0 February 17th 04 05:42 PM


All times are GMT +1. The time now is 07:31 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"