Cell option when selecting cell

BrendanDixon

Board Regular
Joined
Mar 7, 2010
Messages
174
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi All,

I am creating a sheet with 2 columns and if I select the column it will fill it with an X and clear the other column please can someone help me with the part where is will clear only the other cell in that row. I could use allot of code to do each row individually. but I am sure there is a better way of doing this so I can learn from this. basically it will be from rows 18 to 34 and columns B and C

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim Cell As Range
If Not Intersect(Target, Range("B18:C34")) Is Nothing Then
    Cancel = True
    For Each Cell In Range("B18:C34")
      If Not Intersect(Cell, Target) Is Nothing Then
        Cell.Value = "X"
      Else
      'This is where to clear other cell in the row
        Cell.MergeArea.ClearContents ' This will need to change
      End If
      
Next

  End If
 
 
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Does this do what you're looking for?
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells.CountLarge = 1 And Not Intersect(Range("B18:C34"), Target) Is Nothing Then
        Application.EnableEvents = False
        Target = "X"
        With Target
            If .Column = 2 Then .Offset(0, 1).ClearContents
            If .Column = 3 Then .Offset(0, -1).ClearContents
        End With
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,849
Members
449,194
Latest member
HellScout

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