Clean column if emty header

doriannjeshi

Active Member
Joined
Apr 5, 2015
Messages
301
Office Version
  1. 365
Platform
  1. Windows
Hi,
I need a macro that Cleans the column of all content, formats if emty header , to the last column of the range.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi,
I need a macro that Cleans the column of all content, formats if emty header , to the last column of the range.
Assuming that the header is in row 1.

Try this on a copy of your data.

Change the sheet name where indicated.

VBA Code:
Private Sub subClearAll()
Dim rng As Range

  ActiveWorkbook.Save

  For Each rng In Worksheets("Sheet1").UsedRange.Rows(1).Cells '<- Change 'Sheet1' to your sheet name.

    If Len(Trim(rng.Value)) = 0 Then
    
      rng.EntireColumn.Cells.Clear
  
    End If

  Next rng
  
End Sub
 
Upvote 0
Assuming that the header is in row 1.

Try this on a copy of your data.

Change the sheet name where indicated.

VBA Code:
Private Sub subClearAll()
Dim rng As Range

  ActiveWorkbook.Save

  For Each rng In Worksheets("Sheet1").UsedRange.Rows(1).Cells '<- Change 'Sheet1' to your sheet name.

    If Len(Trim(rng.Value)) = 0 Then
   
      rng.EntireColumn.Cells.Clear
 
    End If

  Next rng
 
End Sub
1732116907421.png
 
Upvote 0
Book2
BCDEFGHIJKLMNOPQRST
1AQTBTGATOARIAVLADRAFRAKOASHALUALEITGITOIMSIVLIOX
Sheet1
That's strange as it works for me. Try this code.

VBA Code:
Private Sub subClearAllV2()
Dim rng As Range

  ActiveWorkbook.Save

  For Each rng In Worksheets("Sheet1").UsedRange.Rows(1).Cells '<- Change 'Sheet1' to your sheet name.

    If IsEmpty(rng.Value) Then
    
      rng.EntireColumn.Cells.Clear
  
    End If

  Next rng
  
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,924
Messages
6,175,419
Members
452,640
Latest member
steveridge

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