+ Reply to Thread
Results 1 to 5 of 5

VBA code to delete blank columns (with header)

  1. #1
    Registered User
    Join Date
    06-18-2019
    Location
    Dallas, Texas
    MS-Off Ver
    windows 2013
    Posts
    72

    VBA code to delete blank columns (with header)

    Hello All,

    I have a worksheet full of data and after all my current macros run, I am sometimes left with entire blank columns.
    Headers are on Row+2

    For example: Column: A ( data starts in cell A3, due to header in A2) has data under the header all the way to A300; This goes up until Column S, where (under the header) there is not a single cell below with data.

    This data changes daily when I run the macro with different raw data (not always column S empty).

    Would there be a formula to go through and delete columns that do not have data underneath the header? in order to include this at the end to clean up my worksheet

    Thanks!

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,860

    Re: VBA code to delete blank columns (with header)

    This should do it for you
    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    06-18-2019
    Location
    Dallas, Texas
    MS-Off Ver
    windows 2013
    Posts
    72

    Re: VBA code to delete blank columns (with header)

    I am unsure what went wrong. Could you help explain the lines of code you used in words, in ensure I am using it correctly? Why did you use the "left"? Also where do I put the Option Explicit?
    Last edited by Tgbell; 06-26-2019 at 05:03 PM.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,860

    Re: VBA code to delete blank columns (with header)

    Explanation in code

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-18-2019
    Location
    Dallas, Texas
    MS-Off Ver
    windows 2013
    Posts
    72

    Re: VBA code to delete blank columns (with header)

    why did you set 'lr' (last row) for column 2? The code is not getting any errors, but it is not deleting anything. For example, my data today
    Has (A2:N99) O (blank), Pull (full of data), Q (blank). The columns that are blank can be different everyday. I am sorry for asking again, but my mind cannot get around this. Thanks so much for helping.

    A1

    2: HEADER

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Delete Multiple Columns based on Header Name
    By kingsdime29x in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-13-2019, 04:07 AM
  2. [SOLVED] Delete columns if row header does not equal certain values
    By stevoDE in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-28-2017, 09:34 AM
  3. [SOLVED] dynamic vba code to delete duplicate headers, blank headers and blank columns
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-14-2017, 02:27 PM
  4. [SOLVED] can some one delete the header from this COde
    By sai0449 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-09-2015, 12:36 PM
  5. [SOLVED] VBA Find last row and column that contain data and delete all blank rows and blank columns
    By bcn1988 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-03-2012, 01:07 PM
  6. macro to delete blank columns - includes header row
    By bluesea in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-31-2012, 12:18 PM
  7. Delete Columns Based on Header
    By MSmithson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-28-2010, 03:19 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1