Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Runtime Error 1004 | Excel Discussion (Misc queries) | |||
Runtime error 1004 | Excel Discussion (Misc queries) | |||
runtime error 1004 HELP PLS | Excel Discussion (Misc queries) | |||
Runtime Error '1004' | Excel Discussion (Misc queries) | |||
Runtime Error 1004 | Excel Programming |