View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Selection.ClearContents makes macro halt???

In my previous post I indicated that you had left out some of the code in
your post. Is it running from a Userform? There are some conditions when code
runs from a Userform if it comes across an error then the code appears to
simply abort instead of stopping on the error.

My thoughts are that for some reason your original problem was because the
range could not be selected. In my previous answer I should have been more
specific and said to include the sheet name in the code instead of just
saying it will run on the active sheet.

The sheet name is included with both of the following examples although the
latter is the more professional. Replace "Sheet1" with your sheet name.

Sheets("Sheet1").Range("A3:N300").ClearContents
Sheets("Sheet1").Range("A3:N300").NumberFormat = "@"

or

'Note the dot in from of Range which ties it to Sheets("Sheet1")
With Sheets("Sheet1")
.Range("A3:N300").ClearContents
.Range("A3:N300").NumberFormat = "@"
End With

Using the above methods neither the sheet nor the range need to be selected.

--
Regards,

OssieMac