Link to home
Start Free TrialLog in
Avatar of Euro5
Euro5Flag for United States of America

asked on

VBA remove all data in columns except header

I need to reduce the size of my file by removing unnecessary data.
I need a code to remove data in multiple columns, but leave the headers in place.
Can anyone help?

Need to remove data from row 2 down for columns B, C, D, E, G, H, I, K, L.
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Euro5

ASKER

@Martin,
Concerned that the second time it runs, it just gets stuck.
Why do you think?
Can we check if B2 is populated - then run, if not, then move on?
I can do it two (or 3 or 4 or more) times in a row with no problem but as you suggest this would also work.

Dim lngLast As Long

If Range("B2") = "" Then Exit Sub
lngLast = ActiveSheet.UsedRange.Rows.Count
ActiveSheet.Range("B2:E" & lngLast).ClearContents
ActiveSheet.Range("G2:I" & lngLast).ClearContents
ActiveSheet.Range("K2:L" & lngLast).ClearContents

Open in new window