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
 
Hi, Joe4

Thanks for your kind support.
I made some changes in my code and it works perfectly.

Thanks again.
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
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,221,810
Messages
6,162,108
Members
451,743
Latest member
matt3388

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