VBA Clear data in cell

caritx

New Member
Joined
Dec 1, 2009
Messages
34
PictureDeviceIndependentBitmap1-1.jpg


If column A has value and column B is Blank I want to clear the data in C & D. The problem is I only want to clear the data in that cell and not the whole row of the columns after. Can anyone offer any advice?

Thanks in advance!
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Code:
Sub test()
Dim c As Range
For Each c In Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
    If c <> "" And c.Offset(, 1) = "" Then c.Offset(, 2).Resize(, 2).ClearContents
Next
End Sub
 
Upvote 0
It worked when I tested it. It deletes the values in Column C and D for the rows where Column A is not blank and Column B is. What happened when you ran it?
 
Upvote 0
Before running macro:

Excel Workbook
ABCDE
1123xIIA
2150IIA
3IIA
Sheet1



After:

Excel Workbook
ABCDE
1123xIIA
2150A
3IIA
Sheet1


Is this not what you want?
 
Upvote 0

Forum statistics

Threads
1,215,517
Messages
6,125,288
Members
449,218
Latest member
Excel Master

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