Delete column if row has blank cells

Tija

New Member
Joined
Apr 19, 2022
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Is there any way, the columns can be deleted using a formula or VBA code when the cell is blank in the row? e.g. Row 4 has a blank cell AC4:AE4 and these columns needs to be deleted.


Date Auto Populate.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAE
1MMM-YYFeb-23
2
3
426-Feb27-Feb28-Feb01-Mar02-Mar03-Mar04-Mar05-Mar06-Mar07-Mar08-Mar09-Mar10-Mar11-Mar12-Mar13-Mar14-Mar15-Mar16-Mar17-Mar18-Mar19-Mar20-Mar21-Mar22-Mar23-Mar24-Mar25-Mar
Delete Column
Cell Formulas
RangeFormula
A4:AB4A4=LET(s,DATE(YEAR(B1),MONTH(B1),26),SEQUENCE(,DATE(YEAR(B1),MONTH(B1)+1,26)-s,s))
Dynamic array formulas.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
VBA Code:
Sub deletecolumn()
Range(Cells(4, "A"), Cells(4, "AE")).SpecialCells(xlCellTypeBlanks).EntireColumn.Delete
End Sub
 
Upvote 0
Solution
It worked :) Thank you bebo021999.

Can I get back 31 columns when I select a month from drop down menu which has 31 days? Any VBA code that would be able to handle that condition? Please see the below example

Date Auto Populate.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAI
1MMM-YYMay-2022
2
3Sr.No.Emp IDName01-May02-May03-May04-May05-May06-May07-May08-May09-May10-May11-May12-May13-May14-May15-May16-May17-May18-May19-May20-May21-May22-May23-May24-May25-May26-May27-May28-May29-May30-May31-MayTotal Days
Delete Column 2
Cell Formulas
RangeFormula
D3:AH3D3=IF(B1="","",LET(s,DATE(YEAR(B1),MONTH(B1),1),SEQUENCE(,DATE(YEAR(B1),MONTH(B1)+1,1)-s,s)))
Dynamic array formulas.
Cells with Data Validation
CellAllowCriteria
B1List=Sheet4!$A$1:$A$24
 
Upvote 0
using hide column
VBA Code:
Sub deletecolumn()
Range(Cells(4, "A"), Cells(4, "AE")).SpecialCells(xlCellTypeBlanks).EntireColumn.hidden=true
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,573
Members
449,089
Latest member
Motoracer88

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