Euro5
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
ASKER
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?