+ Reply to Thread
Results 1 to 8 of 8

Delete Columns( From One Sheet) based on the header name from a list.

  1. #1
    Registered User
    Join Date
    03-09-2013
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    8

    Delete Columns( From One Sheet) based on the header name from a list.

    Hi There,

    I have the below scenario.

    Sheet 1 has four columns and following the values in the row .( Name , Address, ID, Company)
    At times , Name column needs to be deleted; Some times , Address column needs to be deleted.
    So, there should a second sheet2. In here , Column A1 can have Name, Column A2 can have Address.
    Based on this list from Sheet2, Columns in Sheet1 should be deleted. Can someone suggest a macro for this ?

    Thanks

    Below is the code which i tried but Can someone suggest how to pass list from Sheet2 instead of following line in the code

    ColAry = Array("Name", "Id")

    I need a ColAry = Array ( I want to pass a range from Sheet2 A1:A2 )

    -----------------------------------------------

    Sub DeleteColumns()
    Dim ColAry, i As Long, fc As Long
    Application.ScreenUpdating = False
    ColAry = Array("Name", "Id")
    With Sheets("Sheet1")
    For i = LBound(ColAry) To UBound(ColAry)
    fc = 0
    On Error Resume Next
    fc = Application.Match(ColAry(i), .Rows(1), 0)
    On Error GoTo 0
    If fc > 0 Then
    .Columns(fc).Delete
    End If
    Next i
    End With

    Application.ScreenUpdating = True
    End Sub
    Last edited by v_a_royston; 08-29-2015 at 04:23 PM.

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Delete Columns( From One Sheet) based on the header name from a list.

    Hi royston
    Welcome to the forum
    Try this code
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Registered User
    Join Date
    03-09-2013
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Delete Columns( From One Sheet) based on the header name from a list.

    Thank You , Yasser. That worked perfectly.
    Similarly, I have one more request on concatenation of the very same thing from a list.

    Sheet1:
    Name , Address, ID, Company

    Sheet2:
    A1 Name , A2 Address, A3 ID , A4 Company.

    After running a macro, Sheet 1 column 5 should have the following Name-Address-ID-Company


    Appreciate your help.

    Thanks
    Last edited by v_a_royston; 08-29-2015 at 04:53 PM.

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Delete Columns( From One Sheet) based on the header name from a list.

    Try this
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-09-2013
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Delete Columns( From One Sheet) based on the header name from a list.

    Thanks, Yasser. It is not working.

    Expectation is

    Sheet1:
    ColA ,ColB , ColC,ColD ,ColE
    Row1: Name , Address, ID , Company, <Blanks>
    Row2: aaaaa , bbbbbbb,111 ,ccccc , <Blanks>
    Row3: ddddd , eeeeeee, 333, fffff , <Blanks>

    Sheet2:
    ColA
    Row1 Name
    Row2 ID
    Row3 Company

    Once we run the macro, the results in Sheet1 should be below.
    ColA , ColB , ColC , ColD, ColE
    Row1: Name , Address, ID, Company , Name-ID-Company
    Row2: aaaaa , bbbbbbb,111 ,ccccc ,aaaaa-111-ccccc
    Row3: ddddd , eeeeeee, 333, fffff , ddddd-333-fffff

    Thanks.

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Delete Columns( From One Sheet) based on the header name from a list.

    It's completely different request from the main topic ..You asked to delete the columns based on the list in sheet2 !!

  7. #7
    Registered User
    Join Date
    03-09-2013
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Delete Columns( From One Sheet) based on the header name from a list.

    I understand that Thanks, Yasser. I will post it in the new main topic.

    Thanks.

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Delete Columns( From One Sheet) based on the header name from a list.

    Posted in the related topic

+ 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] Macro to delete columns based on header
    By sfadam in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-25-2015, 05:15 PM
  2. Macro to delete all columns in a workbook based on header name
    By Kencosgrove in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-15-2015, 12:09 PM
  3. [SOLVED] Copy columns based on header (Without header)
    By Michael_BU in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-15-2014, 08:07 AM
  4. [SOLVED] Want to Delete Specified Columns and then add Column header to the remaining ones
    By ppilot in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-16-2014, 12:41 PM
  5. Replies: 2
    Last Post: 10-13-2012, 03:30 AM
  6. Add and Delete Sheets based on contents of list located in the first sheet
    By gophins in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-09-2012, 03:50 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