On Thu, 31 Jul 2008 15:14:00 -0700, Jim Thomlinson
<James_Thomlinson@owfg-Re-Move-This-.com> wrote:
>Asking before you delete is pretty standard practice... Try something like
>this...
>
>Sub ClearDATA()
>'
> if msgbox("Delete can not be undone. Continue???") = vbno then exit sub
>
> with ActiveSheet
> .Unprotect 'place at the beginning of the code
> .Range("B2
100").ClearContents
> .Range("J2:J100").ClearContents
> .Range("M2:M100").ClearContents
> .Rows("2:" & .Rows.Count).AutoFit
> '.Range("B2").Select
> .Protect 'place at the end of the code
> end with
>End Sub
>
>PS... didn't you used to be StarGateFanFromWork?
Darn, darn, darn. For last few days using this sheet, I've felt it
would be too easy to delete the cell contents despite the caution box
so decided it would be safer to move this button to its own sheet at
the end of the workbook. However, all the codes I've ever used are
for active sheet. I found what I thought was best code from the
archives and modified it to suit my workbook requirements. Here's
where the modified code stands now:
*****************************************************************************
Sub ClearDATAinSUPPLIESsheet()
If MsgBox("You will be deleting the entire supply data from this
sheet! " & vbCrLf & vbCrLf & _
"Do you wish to continue???", _
vbYesNo Or vbDefaultButton2) = vbNo Then Exit Sub
ThisWorkbook.Worksheets("Supplies").Unprotect
With ActiveSheet
' .Unprotect 'place at the beginning of the code
.Range("B2

100").ClearContents
.Range("J2:J100").ClearContents
' .Rows("2:" & .Rows.Count).AutoFit
.Range("B2").Select
' .Protect 'place at the end of the code
End With
Sheets("SUPPLIES").Cells.EntireColumn.AutoFit
ThisWorkbook.Worksheets("Supplies").Protect
End Sub
*****************************************************************************
But not sure what is right or not in my modifications since I'm still
getting the same 1004 error as when I just moved the button:
" Run-time error '1004':
Cannot change part of a merged cell."
There are no merged cells in the target sheet. There is on the one
the button is located on now.
Anyway, if I go ahead and debug, this line is highlighted:
.Range("B2

100").ClearContents
? I double-checked ranges and what is seen in the script above is
valid. All these cell can have contents removed. They're not
protected and not merged cells.
Any clues?