Clear value once active cell is then not active

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
Morning,

Can you be of assistance to alter the following code supplied.
I wish to clear contents of the active cell B13 once its no longer the active cell.

Have a nice day.

Code:
[B][COLOR=#0000FF][FONT=verdana]​Sub sbClearCellOnlyData()[/FONT][/COLOR]
[/B][FONT=Arial][SIZE=2][COLOR=#3333FF][B][COLOR=#0000FF][FONT=verdana]Range("B13").ClearContents[/FONT][/COLOR]
[/B][/COLOR][/SIZE][/FONT]
[B][COLOR=#0000FF][FONT=verdana]End Sub​[/FONT][/COLOR]
[/B]
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
in the main module have variable declared
Code:
Option Explicit
Public RefCell As Boolean

On the sheet concerned
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)


If Target.Address = "$B$2" And RefCell = False Then
    'MsgBox "B2 active"
    RefCell = True
End If
If Target.Address <> "$B$2" And RefCell = True Then
    'MsgBox "B2 inactive"
    RefCell = False
End If


End Sub
 
Last edited:
Upvote 0
this will significantly slow you down. each time you change selection, enter, tab, mouse click, macro will run.

point to cell B13 and hit delete.
 
Upvote 0
Thank,
I have found that out & removing code as i type.
 
Upvote 0
in the main module have variable declared
Code:
Option Explicit
Public RefCell As Boolean

On the sheet concerned
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)


If Target.Address = "$B$2" And RefCell = False Then
    'MsgBox "B2 active"
    RefCell = True
End If
If Target.Address <> "$B$2" And RefCell = True Then
    'MsgBox "B2 inactive"
    RefCell = False
End If


End Sub

Sorry, need to change $B$2 to $B$13
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top