Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Clearing target cells:

Hi,

This program works great except for when I clear any cell in the target
range a (Run-Time error €˜1004: Application-defined or object-defined error)
message pops up. Can this be rewritten to except a blank cell or cell
E5=1,E6=2 and so on when cells are cleared of players names.

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("E5:E16")) Is Nothing Then
Worksheets(Target.Row - 2).Name = Target.Value
End If

End Sub

Thanks Charles.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Clearing target cells:

There are lots of other things that could go wrong--besides just emptying that
cell. If you put something in that cell that is invalid in a worksheet name
(colon, slash, backslash or even an existing worksheet name), your code will get
sick.

Maybe just trying and catching the error would be better.

Private Sub Worksheet_Change(ByVal Target As Range)

'only one cell at a time!
if target.cells.count 1 then exit sub

If Not Intersect(Target, me.Range("E5:E16")) Is Nothing Then
on error resume next 'let it try to rename it
Worksheets(Target.Row - 2).Name = Target.Value
if err.number < 0 then
msgbox "something bad happened!"
beep
err.clear
end if
on error goto 0
End If

End Sub



Charles wrote:

Hi,

This program works great except for when I clear any cell in the target
range a (Run-Time error €˜1004: Application-defined or object-defined error)
message pops up. Can this be rewritten to except a blank cell or cell
E5=1,E6=2 and so on when cells are cleared of players names.

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("E5:E16")) Is Nothing Then
Worksheets(Target.Row - 2).Name = Target.Value
End If

End Sub

Thanks Charles.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Clearing target cells:



"Dave Peterson" wrote:

There are lots of other things that could go wrong--besides just emptying that
cell. If you put something in that cell that is invalid in a worksheet name
(colon, slash, backslash or even an existing worksheet name), your code will get
sick.

Maybe just trying and catching the error would be better.

Private Sub Worksheet_Change(ByVal Target As Range)

'only one cell at a time!
if target.cells.count 1 then exit sub

If Not Intersect(Target, me.Range("E5:E16")) Is Nothing Then
on error resume next 'let it try to rename it
Worksheets(Target.Row - 2).Name = Target.Value
if err.number < 0 then
msgbox "something bad happened!"
beep
err.clear
end if
on error goto 0
End If

End Sub



Charles wrote:

Hi,

This program works great except for when I clear any cell in the target
range a (Run-Time error €˜1004€„¢: Application-defined or object-defined error)
message pops up. Can this be rewritten to except a blank cell or cell
E5=1,E6=2 and so on when cells are cleared of players names.

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("E5:E16")) Is Nothing Then
Worksheets(Target.Row - 2).Name = Target.Value
End If

End Sub

Thanks Charles.


--

Dave Peterson

Dave,

Thank you for fixing my problem and pointing out other existing handicaps
with this program. Its working great now.

Thanks again.

Charles,

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
Clearing cells without clearing formulas marsjune68 Excel Discussion (Misc queries) 2 April 10th 09 07:39 PM
clearing cells Lauren Excel Worksheet Functions 1 September 7th 06 09:41 PM
Clearing cells [email protected] Excel Programming 1 January 4th 06 09:48 PM
Clearing Cells mully New Users to Excel 3 May 19th 05 07:12 PM
Clearing cells hal Excel Programming 3 August 8th 03 04:01 PM


All times are GMT +1. The time now is 04:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"