Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Tweak to clear button code needed

In my spreadsheet, I have a clear button (coded below). The whole
sheet (all cells) are locked except range E5 - E12 , G3 and G5
through G12 which are unlocked.

What I want to do upon click of the clear button is for the the
cells in E5-E12 & G3 to be cleared leaving the unprotected cell
range G5 through G12 uncleared then of course leaving all other
locked cells alone. What can I add or change in my code to
accomplish this?


Private Sub ClearButton1_Click()

Dim cell As Range
Range("E5:E12", "G3").Select

For Each cell In Selection
If cell.Locked = False Then
cell.ClearContents
End If

Range("G3").Select
Range("G3").Activate

Next
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Tweak to clear button code needed

If I understand your setup correctly, I would think this subroutine would do
what you want...

Sub ClearButton1_Click()
Union(Range("E5:E12"), Range("G3")).ClearContents
Range("G3").Select
End Sub

Rick


"Jcraig713" wrote in message
...
In my spreadsheet, I have a clear button (coded below). The whole
sheet (all cells) are locked except range E5 - E12 , G3 and G5
through G12 which are unlocked.

What I want to do upon click of the clear button is for the the
cells in E5-E12 & G3 to be cleared leaving the unprotected cell
range G5 through G12 uncleared then of course leaving all other
locked cells alone. What can I add or change in my code to
accomplish this?


Private Sub ClearButton1_Click()

Dim cell As Range
Range("E5:E12", "G3").Select

For Each cell In Selection
If cell.Locked = False Then
cell.ClearContents
End If

Range("G3").Select
Range("G3").Activate

Next
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Tweak to clear button code needed

Hi,
Seems like the cells you are trying to clear are already unlocked.
Also, 99% of the time, when you process cells, you do Not need to select
them first.
So your code would be simply:
Range("E5:E12,G3").ClearContents

(no need to re-select or activate any cell since the above code didn't
change the selection)
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Jcraig713" wrote:

In my spreadsheet, I have a clear button (coded below). The whole
sheet (all cells) are locked except range E5 - E12 , G3 and G5
through G12 which are unlocked.

What I want to do upon click of the clear button is for the the
cells in E5-E12 & G3 to be cleared leaving the unprotected cell
range G5 through G12 uncleared then of course leaving all other
locked cells alone. What can I add or change in my code to
accomplish this?


Private Sub ClearButton1_Click()

Dim cell As Range
Range("E5:E12", "G3").Select

For Each cell In Selection
If cell.Locked = False Then
cell.ClearContents
End If

Range("G3").Select
Range("G3").Activate

Next
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Tweak to clear button code needed

This works great, actually both suggestions worked well. What would you say
would be a suggestion to clear the cells I have spoke to and also reset a
additional range of cells to = a formula? Currently, one set of cells has an
if statement in the cell but the use can insert whatever value they need. I
would like my clear button to clear the cells as originally indicated but
also reset cells G5-G12 to =
=IF(ISBLANK(E5),0,IF(E5="NM",0,IF(E5="CR",0,G$3))) on click.

"sebastienm" wrote:

Hi,
Seems like the cells you are trying to clear are already unlocked.
Also, 99% of the time, when you process cells, you do Not need to select
them first.
So your code would be simply:
Range("E5:E12,G3").ClearContents

(no need to re-select or activate any cell since the above code didn't
change the selection)
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Jcraig713" wrote:

In my spreadsheet, I have a clear button (coded below). The whole
sheet (all cells) are locked except range E5 - E12 , G3 and G5
through G12 which are unlocked.

What I want to do upon click of the clear button is for the the
cells in E5-E12 & G3 to be cleared leaving the unprotected cell
range G5 through G12 uncleared then of course leaving all other
locked cells alone. What can I add or change in my code to
accomplish this?


Private Sub ClearButton1_Click()

Dim cell As Range
Range("E5:E12", "G3").Select

For Each cell In Selection
If cell.Locked = False Then
cell.ClearContents
End If

Range("G3").Select
Range("G3").Activate

Next
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Tweak to clear button code needed

One line of code:

Range("G5:G12").Formula =
"=IF(ISBLANK(E5),0,IF(E5="NM",0,IF(E5="CR",0,G$3)) )"

Since E5 is a relative addres (and not $E$5) , excel automatically uses:
- E5 in the formula for cell G5
- E6 in the formula for cell G6
- E7 in the formula for cell G7
- ...
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Jcraig713" wrote:

This works great, actually both suggestions worked well. What would you say
would be a suggestion to clear the cells I have spoke to and also reset a
additional range of cells to = a formula? Currently, one set of cells has an
if statement in the cell but the use can insert whatever value they need. I
would like my clear button to clear the cells as originally indicated but
also reset cells G5-G12 to =
=IF(ISBLANK(E5),0,IF(E5="NM",0,IF(E5="CR",0,G$3))) on click.

"sebastienm" wrote:

Hi,
Seems like the cells you are trying to clear are already unlocked.
Also, 99% of the time, when you process cells, you do Not need to select
them first.
So your code would be simply:
Range("E5:E12,G3").ClearContents

(no need to re-select or activate any cell since the above code didn't
change the selection)
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Jcraig713" wrote:

In my spreadsheet, I have a clear button (coded below). The whole
sheet (all cells) are locked except range E5 - E12 , G3 and G5
through G12 which are unlocked.

What I want to do upon click of the clear button is for the the
cells in E5-E12 & G3 to be cleared leaving the unprotected cell
range G5 through G12 uncleared then of course leaving all other
locked cells alone. What can I add or change in my code to
accomplish this?


Private Sub ClearButton1_Click()

Dim cell As Range
Range("E5:E12", "G3").Select

For Each cell In Selection
If cell.Locked = False Then
cell.ClearContents
End If

Range("G3").Select
Range("G3").Activate

Next
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Tweak to clear button code needed

In relation then to the following code, where would you put the line of code
you suggest. I think I am putting it in the wrong area becuase I am getting
a compile error when I try and place it:

Private Sub ClearButton1_Click()

Dim ocell As Range
Range("G3").ClearContents

For Each ocell In Range("E5:E12")
ocell.ClearContents

Range("G5:G12").Formula =
"=IF(ISBLANK(E5),0,IF(E5="NM",0,IF(E5="CR",0,G$3)) )"

Range("G3").Select
Range("G3").Activate

Next ocell
End Sub



"sebastienm" wrote:

One line of code:

Range("G5:G12").Formula =
"=IF(ISBLANK(E5),0,IF(E5="NM",0,IF(E5="CR",0,G$3)) )"

Since E5 is a relative addres (and not $E$5) , excel automatically uses:
- E5 in the formula for cell G5
- E6 in the formula for cell G6
- E7 in the formula for cell G7
- ...
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Jcraig713" wrote:

This works great, actually both suggestions worked well. What would you say
would be a suggestion to clear the cells I have spoke to and also reset a
additional range of cells to = a formula? Currently, one set of cells has an
if statement in the cell but the use can insert whatever value they need. I
would like my clear button to clear the cells as originally indicated but
also reset cells G5-G12 to =
=IF(ISBLANK(E5),0,IF(E5="NM",0,IF(E5="CR",0,G$3))) on click.

"sebastienm" wrote:

Hi,
Seems like the cells you are trying to clear are already unlocked.
Also, 99% of the time, when you process cells, you do Not need to select
them first.
So your code would be simply:
Range("E5:E12,G3").ClearContents

(no need to re-select or activate any cell since the above code didn't
change the selection)
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Jcraig713" wrote:

In my spreadsheet, I have a clear button (coded below). The whole
sheet (all cells) are locked except range E5 - E12 , G3 and G5
through G12 which are unlocked.

What I want to do upon click of the clear button is for the the
cells in E5-E12 & G3 to be cleared leaving the unprotected cell
range G5 through G12 uncleared then of course leaving all other
locked cells alone. What can I add or change in my code to
accomplish this?


Private Sub ClearButton1_Click()

Dim cell As Range
Range("E5:E12", "G3").Select

For Each cell In Selection
If cell.Locked = False Then
cell.ClearContents
End If

Range("G3").Select
Range("G3").Activate

Next
End Sub

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Tweak to clear button code needed

Try this subroutine (which uses what Sébastien has posted) instead of the
one you posted...

Sub ClearButton1_Click()
Range("E5:E12,G3").ClearContents
Range("G5:G12").Formula = _
"=IF(ISBLANK(E5),0,IF(E5=""NM"",0,IF(E5=""CR"",0,G $3)))"
Range("G3").Select
End Sub

Note: In case you are comparing the function assignment statement, I doubled
up the internal quote marks from Sébastien's posted code so that VBA could
properly handle them.

Rick


"Jcraig713" wrote in message
...
In relation then to the following code, where would you put the line of
code
you suggest. I think I am putting it in the wrong area becuase I am
getting
a compile error when I try and place it:

Private Sub ClearButton1_Click()

Dim ocell As Range
Range("G3").ClearContents

For Each ocell In Range("E5:E12")
ocell.ClearContents

Range("G5:G12").Formula =
"=IF(ISBLANK(E5),0,IF(E5="NM",0,IF(E5="CR",0,G$3)) )"

Range("G3").Select
Range("G3").Activate

Next ocell
End Sub



"sebastienm" wrote:

One line of code:

Range("G5:G12").Formula =
"=IF(ISBLANK(E5),0,IF(E5="NM",0,IF(E5="CR",0,G$3)) )"

Since E5 is a relative addres (and not $E$5) , excel automatically uses:
- E5 in the formula for cell G5
- E6 in the formula for cell G6
- E7 in the formula for cell G7
- ...
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Jcraig713" wrote:

This works great, actually both suggestions worked well. What would
you say
would be a suggestion to clear the cells I have spoke to and also reset
a
additional range of cells to = a formula? Currently, one set of cells
has an
if statement in the cell but the use can insert whatever value they
need. I
would like my clear button to clear the cells as originally indicated
but
also reset cells G5-G12 to =
=IF(ISBLANK(E5),0,IF(E5="NM",0,IF(E5="CR",0,G$3))) on click.

"sebastienm" wrote:

Hi,
Seems like the cells you are trying to clear are already unlocked.
Also, 99% of the time, when you process cells, you do Not need to
select
them first.
So your code would be simply:
Range("E5:E12,G3").ClearContents

(no need to re-select or activate any cell since the above code
didn't
change the selection)
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Jcraig713" wrote:

In my spreadsheet, I have a clear button (coded below). The whole
sheet (all cells) are locked except range E5 - E12 , G3 and G5
through G12 which are unlocked.

What I want to do upon click of the clear button is for the the
cells in E5-E12 & G3 to be cleared leaving the unprotected cell
range G5 through G12 uncleared then of course leaving all other
locked cells alone. What can I add or change in my code to
accomplish this?


Private Sub ClearButton1_Click()

Dim cell As Range
Range("E5:E12", "G3").Select

For Each cell In Selection
If cell.Locked = False Then
cell.ClearContents
End If

Range("G3").Select
Range("G3").Activate

Next
End Sub


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Tweak to clear button code needed

Sub ClearButton1_Click()
Range("E5:E12,G3").ClearContents
Range("G5:G12").Formula = _
"=IF(ISBLANK(E5),0,IF(E5=""NM"",0,IF(E5=""CR"",0,G $3)))"
Range("G3").Select
End Sub
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Jcraig713" wrote:

In relation then to the following code, where would you put the line of code
you suggest. I think I am putting it in the wrong area becuase I am getting
a compile error when I try and place it:

Private Sub ClearButton1_Click()

Dim ocell As Range
Range("G3").ClearContents

For Each ocell In Range("E5:E12")
ocell.ClearContents

Range("G5:G12").Formula =
"=IF(ISBLANK(E5),0,IF(E5="NM",0,IF(E5="CR",0,G$3)) )"

Range("G3").Select
Range("G3").Activate

Next ocell
End Sub



"sebastienm" wrote:

One line of code:

Range("G5:G12").Formula =
"=IF(ISBLANK(E5),0,IF(E5="NM",0,IF(E5="CR",0,G$3)) )"

Since E5 is a relative addres (and not $E$5) , excel automatically uses:
- E5 in the formula for cell G5
- E6 in the formula for cell G6
- E7 in the formula for cell G7
- ...
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Jcraig713" wrote:

This works great, actually both suggestions worked well. What would you say
would be a suggestion to clear the cells I have spoke to and also reset a
additional range of cells to = a formula? Currently, one set of cells has an
if statement in the cell but the use can insert whatever value they need. I
would like my clear button to clear the cells as originally indicated but
also reset cells G5-G12 to =
=IF(ISBLANK(E5),0,IF(E5="NM",0,IF(E5="CR",0,G$3))) on click.

"sebastienm" wrote:

Hi,
Seems like the cells you are trying to clear are already unlocked.
Also, 99% of the time, when you process cells, you do Not need to select
them first.
So your code would be simply:
Range("E5:E12,G3").ClearContents

(no need to re-select or activate any cell since the above code didn't
change the selection)
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Jcraig713" wrote:

In my spreadsheet, I have a clear button (coded below). The whole
sheet (all cells) are locked except range E5 - E12 , G3 and G5
through G12 which are unlocked.

What I want to do upon click of the clear button is for the the
cells in E5-E12 & G3 to be cleared leaving the unprotected cell
range G5 through G12 uncleared then of course leaving all other
locked cells alone. What can I add or change in my code to
accomplish this?


Private Sub ClearButton1_Click()

Dim cell As Range
Range("E5:E12", "G3").Select

For Each cell In Selection
If cell.Locked = False Then
cell.ClearContents
End If

Range("G3").Select
Range("G3").Activate

Next
End Sub

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
Need someone to help tweak a code JB Excel Discussion (Misc queries) 13 January 17th 08 03:04 PM
shorten connection time <<Macro Tweak needed Dan Excel Programming 0 April 17th 07 07:47 AM
clear option buttons **MACRO TWEAK** Dan Excel Programming 4 February 19th 07 05:34 PM
Code Tweak bodhisatvaofboogie Excel Programming 1 July 21st 06 04:37 PM
Need final code tweak Phil Hageman Excel Programming 12 August 16th 03 08:53 PM


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