VB Script IF field is blank

Tmod4eva

New Member
Joined
Feb 10, 2012
Messages
2
Hi,

Even though this is my first post to this forum, I have visited and browsed these forums many times and have been helped from the questions that others have asked.

I am having trouble trying to write a VB script (as I am new to VB) to blank out (delete) information from one cell IF another is cell is also empty.

Example:
--IF A1 does not contain any data, Then Delete any information from column B1.

The problem however is that column B currently contains data and I do not want to delete all data from these cells IF column A in the same row also has data. This is why I think a VB script would work best.

Thank you for all your help.

-Ricky
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi Ricky and welcome to the Board
try
Code:
Sub clrcel()
Dim lr As Long, r As Long
    For r = Cells(Rows.Count, "A").End(xlUp).Row To 1 Step -1
        If Range("A" & r).Value = "" Then Range("B" & r).ClearContents
    Next r
End Sub
 
Upvote 0
Glad it worked, thanks for the feedback...(y)
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,840
Members
449,193
Latest member
MikeVol

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