Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Why I got this 1004 runtime error


You probably got the error because your worksheet wasn't active. You
can't select cells on a worksheet that isn't active. Change your macro to
the following and it will work regardless of whether the worksheet is active
or not:

Sub ClrSht(ShtNm)
With Sheets(ShtNm)
.Cells.ClearContents
End With
End Sub

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"hcova" wrote in message
...
I am trying to write a procedure that clear all in a sheet before write

something on it. I wrote the following code:
---------------------------
Option Explicit

Const MySht As String = "Sheet1" ' this is a valid sheet name in the

workbook

Sub ClrSht(ShtNm)
With Sheets(ShtNm)
.Cells.Select ' <== Here I receive the error !!!
Selection.ClearContents
End With
End Sub

Sub CallClrSht()
ClrSht(MySht)
End Sub
------------------------------

Anybody can explain me why I am getting a runtime error?
Regards



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
Runtime Error 1004 JB Bates[_2_] Excel Discussion (Misc queries) 5 December 29th 09 02:40 PM
Runtime error 1004 JR Excel Discussion (Misc queries) 2 November 21st 08 08:29 PM
runtime error 1004 HELP PLS Marcelo P Excel Discussion (Misc queries) 2 May 23rd 07 08:56 PM
Runtime Error '1004' [email protected] Excel Discussion (Misc queries) 2 July 18th 05 06:10 AM
Runtime Error 1004 Don[_7_] Excel Programming 2 September 16th 03 08:32 AM


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