Goldman1965
New Member
- Joined
- Jun 9, 2013
- Messages
- 25
Hi Guys,
I have two tables in one of my worksheets, where if I click on cell in Row A, using a command button (which I've created), that same active cell along with cell B (immediately to the right) the contents will be automatically cleared. Additionally, I want to achieve the same clear contents command button to clear the contents in an active cell in Row I along with cell J (immediately to its right). So essentially, performing two separate commands using the same command button.
Here's my code which doesn't work as it only clears contents in the adjacent rows I and J even when I click on Row A or B (any help would be greatly appreciated):
I have two tables in one of my worksheets, where if I click on cell in Row A, using a command button (which I've created), that same active cell along with cell B (immediately to the right) the contents will be automatically cleared. Additionally, I want to achieve the same clear contents command button to clear the contents in an active cell in Row I along with cell J (immediately to its right). So essentially, performing two separate commands using the same command button.
Here's my code which doesn't work as it only clears contents in the adjacent rows I and J even when I click on Row A or B (any help would be greatly appreciated):
Code:
Private Sub CommandButton1_Click()
If MyRow = ActiveCell.Row Then
Range("A" & MyRow & ":B" & MyRow).ClearContents
Else
MyRow = ActiveCell.Row
Range("I" & MyRow & ":J" & MyRow).ClearContents
Application.CutCopyMode = False
End If
End Sub