Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Delete special cells base on criteria such as blanks or highlights

I have some reports that need to be modified by deleting some specific cells such as blank cells or highlights in the background

I have tried to record Macro to delete the special cells. however, the position will be changed regarding the difference of the row numbers. I could not specify the certain position of each cell.

Here is my data

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

here is what I expect to get

enter image description here

Here is my recorded Macro

`Sub Macro1()

‘Macro1 Macro

Range("B4").Select
Selection.Delete Shift:=xlToLeft
Range("B16").Select
Selection.Delete Shift:=xlUp
Range("B24").Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.SmallScroll Down:=12
Range("B30").Select
Selection.Delete Shift:=xlToLeft

End Sub`

>Solution :

You can try the below, change the columns you want to delete

you can change criteria by using xlcelltype XXXX

for xample of xlcelltype

enter image description here

Dim b As Range

For Each b In [B1:B2000].SpecialCells(xlCellTypeBlanks, 1).Offset(0, -1).Areas
    b.Delete Shift:=xlToLeft
Next
    
    
    Cells.Select
    Cells.EntireColumn.Autofit

        
End Sub
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading