VBA clear column if 1st row is blank

Akbarov

Active Member
Joined
Jun 30, 2018
Messages
347
Office Version
  1. 365
Platform
  1. Windows
Hello Dear community,

I use following VBA to clear whole column if 1st row is blank.
It works perfectly fine.
Problem is I need it to delete no whole column. But from row 3 to row 60 and also from row 500 to row 1000.
Can anyone help me modify this code to achieve that ?

VBA Code:
Sub Clear_Out()
Application.ScreenUpdating = False
Dim c As Range
    For Each c In Range("F2:TY2")
        If c.Value = xlnullstring Then
            c.Resize(54, 1).Value = xlnullstring
        End If
    Next
Application.ScreenUpdating = True
 
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Nevermind macro. Can you show me better way to do that?
 
Upvote 0
How about
VBA Code:
Sub Clear_Out()
If Range("F1") = "" Then Range("F3:F60,F500:F1000").Clear
End Sub
 
Upvote 0
VBA Code:
Sub Clear_Out()
Application.ScreenUpdating = False
Dim c As Range
    For Each c In Range("F2:TY2")
        If c.Value = "" Then
            c.Resize(54, 1).ClearContents
            c.Offset(498, 0).Resize(501, 1).ClearContents
        End If
    Next
Application.ScreenUpdating = True
 
End Sub
 
Upvote 0
Solution
Thank you so much Phuoc...

Also Michael I needed code not only for single cell. But thanks for reply.
 
Upvote 0

Forum statistics

Threads
1,215,257
Messages
6,123,916
Members
449,133
Latest member
rduffieldc

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