Clearing cells when another cell becomes populated

Lobz

New Member
Joined
Nov 12, 2022
Messages
10
Office Version
  1. 365
Platform
  1. Windows
I am very new to vba and macros and I am trying to clear cells automatically when another cell gets a value put into it. An example would be: If C3 has a value, clear B3, but I'd like it to do that to an entire table range. I've used this code:
Sub CLEARCELLS()



If Sheet1.Range("C3").Value <> "" Then

Sheet1.Range("B3").ClearContents

End If



End Sub

It works perfect for that particular cell, but I need it to cover all of column B & C and I'm pretty stuck since this is all new to me. Any help would be appreciated, thank you.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
So, when you enter a value in Range("C3") you want columns C and B cleared.
Is that what you want?

So, the value you just entered will be cleared also
 
Upvote 0
Ignore previous post:

This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

If you enter any value in column C the value in same row column B will be cleared
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  11/12/2022  10:11:27 PM  EST
If Target.Column = 3 Then
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
Application.EnableEvents = False
If Target.Value <> "" Then Target.Offset(, -1).Clear
Application.EnableEvents = True
End If
End Sub
 
Upvote 0
You are a gentleman and a scholar. I'm still learning all of this and that is exactly what I needed. The only adjustment I did was change (.clear) to (.clearcontents) to keep my other formatting. Great help and thank you.
 
Upvote 0
ok, it worked great on the tester sheet I set up but when I added it to the sheet, I am applying it to, I think it interferes with another worksheet change I have in place for barcode tracking. Is it possible to have multiple worksheet changes?
 
Upvote 0
No, you can't have multiple worksheet changes on the one sheet, but it may be possible to combine them into 1.
Post the other code you are currently using and someone may be able to help you.
 
Upvote 0
ok, it worked great on the tester sheet I set up but when I added it to the sheet, I am applying it to, I think it interferes with another worksheet change I have in place for barcode tracking. Is it possible to have multiple worksheet changes?
Post all the code you want in this sheet here so I can help.
Yes two sheet change event scripts can be in the same sheet if we post it correctly.
Post those two codes here and I will show you how to combine them
 
Upvote 0
Private Sub Worksheet_Change(ByVal Target As Range)


If Not Intersect(Target, Me.Range("B2")) Is Nothing Then

Call leaving
Application.EnableEvents = True
End If

End Sub
Sub ClearCell()

If IsDate(Range("C4:C1000").Value) Then
MsgBox ("Cells")
End If

End Sub

Sub ClearLocation()

If Range("c4:c1000") <> "" Then
Range("b4:b1000").ClearContents
End If

End Sub

This is the code that I have based of a template I found, I know there is a cleaner way to write this code too, and it is connected to 2 previous sheets that record barcode entries with time in/time out and location. What I am trying to achieve is to have the location column clear on this sheet when it has been scanned out because I have the locations on this sheet linked to another location sheet and I don't want them to remain on the final location page if they have been scanned out.
 
Upvote 0
Private Sub Worksheet_Change(ByVal Target As Range)


If Not Intersect(Target, Me.Range("B2")) Is Nothing Then

Call leaving
Application.EnableEvents = True
End If

End Sub
Sub ClearCell()

If IsDate(Range("C4:C1000").Value) Then
MsgBox ("Cells")
End If

End Sub

Sub ClearLocation()

If Range("c4:c1000") <> "" Then
Range("b4:b1000").ClearContents
End If

End Sub

This is the code that I have based of a template I found, I know there is a cleaner way to write this code too, and it is connected to 2 previous sheets that record barcode entries with time in/time out and location. What I am trying to achieve is to have the location column clear on this sheet when it has been scanned out because I have the locations on this sheet linked to another location sheet and I don't want them to remain on the final location page if they have been scanned out.
This is beyond my knowledgebase.
I will continue to monitor this thread to see what I can learn.
 
Upvote 0
Thank you for your help on the original question. I might have to make a duplicate page or something to run it. I'm still learning and will figure something out.
 
Upvote 0

Forum statistics

Threads
1,214,960
Messages
6,122,479
Members
449,088
Latest member
Melvetica

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