Keep the Cell Blank if another cell is blank in the same row

mamun_ges

Board Regular
Joined
Jul 21, 2016
Messages
58
Hi, Everyone

Hope all are fine.

I am working on a worksheet with some data related to other cells. In this worksheet, if any cell in between W9:W1200 is empty then any data input in the same row of AC and AD will be cleared.

As before, if any cell between X9:X1200 is empty, then any data if input in the same row of AE and AF will be cleared.

Can it done with the VBA? If, please .....
Capture.JPG
I upload an image to better understand my thoughts.

Thanks in advance
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi, joe4
Can I ask something?

Can I change
VBA Code:
For r = 9 To 1200
to something like only what I select from the range.
Then what should I do?
How to change
VBA Code:
For r = 9 To 1200
to something
VBA Code:
r=  Range(Selection.Address) (

Then It will not Loop through rows 9-1200

Thanks in advance
 
Upvote 0
Hi, joe4
Can I ask something?

Can I change
VBA Code:
For r = 9 To 1200
to something like only what I select from the range.
Then what should I do?
How to change
VBA Code:
For r = 9 To 1200
to something
VBA Code:
r=  Range(Selection.Address) (

Then It will not Loop through rows 9-1200

Thanks in advance
If you have selected the range you want, BEING SURE TO ONLY SELECT ONE COLUMN, then you could do something like this:
VBA Code:
Sub MyClearValues()

    Dim cell as Range
    Dim r As Long
   
    Application.ScreenUpdating = False
   
'   Loop through all rows selected in column
    For each cell in Selection
'       Get row number
        r = cell.Row
'       See if column W is empty
        If Cells(r, "W") = "" Then
'           Clear columns AC:AD
            Range(Cells(r, "AC"), Cells(r, "AD")).ClearContents
        End If
'       See if column X is empty
        If Cells(r, "X") = "" Then
'           Clear columns AC:AD
            Range(Cells(r, "AE"), Cells(r, "AF")).ClearContents
        End If
    Next r
   
    Application.ScreenUpdating = True
   
    MsgBox "Macro complete!", vbOKOnly
   
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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