+ Reply to Thread
Results 1 to 18 of 18

Delete Columns where Row 1 is not equal to X or Y

  1. #1
    Registered User
    Join Date
    06-05-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    30

    Delete Columns where Row 1 is not equal to X or Y

    Hello,

    I have a macro that deletes unwanted columns from a raw extract of data. The problem is that the columns order will be random at every extract so a commonly recoreded macro will not work.

    I want to delete any columns where
    Type
    TenderType
    AccountToken
    AccountName
    Activity
    CountDistinct

    is NOT in ROW 1.

    So essentially i will be left with the column above for this specific page.

  2. #2
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Delete Columns where Row 1 is not equal to X or Y

    Hi dhpeter83, try this:
    Please Login or Register  to view this content.
    Kind regards,
    berlan

  3. #3
    Registered User
    Join Date
    06-05-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Delete Columns where Row 1 is not equal to X or Y

    It didn't work. It kept column "type" but no others. If it's helpful, "type" was the first column in the data set that matched the requirements.

  4. #4
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Delete Columns where Row 1 is not equal to X or Y

    hmmm I tested berlans code and it worked fine for me. Heres my alternative code but its in no way as good as berlans.
    Please Login or Register  to view this content.
    Last edited by pjwhitfield; 12-22-2014 at 06:20 PM.
    If someone has helped you then please add to their Reputation

  5. #5
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Delete Columns where Row 1 is not equal to X or Y

    Hi again, in fact it worked for me (in Excel 2013). Otherwise, here's another option:
    Please Login or Register  to view this content.
    Cheers, berlan

  6. #6
    Registered User
    Join Date
    06-05-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Delete Columns where Row 1 is not equal to X or Y

    Yeah I don't know why, it reads as thought it should work, but it's only retaining the type column.. I'm on 2007

    The newer macro froze my excel. Thanks for helping me with this

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,675

    Re: Delete Columns where Row 1 is not equal to X or Y

    Try this with a back up file.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-05-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Delete Columns where Row 1 is not equal to X or Y

    This latest one worked like a charm! Thanks for your help!

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,675

    Re: Delete Columns where Row 1 is not equal to X or Y

    You are welcome and thanks for the rep.


    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  10. #10
    Registered User
    Join Date
    06-05-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Delete Columns where Row 1 is not equal to X or Y

    I have a follow up question for your brilliant minds.

    These columns may not always be in the same order...

    How do I find the column, say, account number, and select it to apply some formatting to it, or cut and paste it to column b from where ever it may be,

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,675

    Re: Delete Columns where Row 1 is not equal to X or Y

    See if this is how you wanted.
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    06-05-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Delete Columns where Row 1 is not equal to X or Y

    Great! This works perfectly to get them in the same order.

    Now how to do i get the column "Acccount Token" to be a number format rather than scientific notation, which is what it is from the raw data,

    and if there was a column with "Date" in it, how do i get it to MM/DD/YY format?

    thanks in advance

  13. #13
    Registered User
    Join Date
    06-05-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Delete Columns where Row 1 is not equal to X or Y

    this doesn't necessarily have to be in the same macro, but rather a different macro to call, to encompass all the pages i may have?

    Find
    "Token" in column, apply number format

    Find Date in columns, apply date format...make sense?

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,675

    Re: Delete Columns where Row 1 is not equal to X or Y

    Need to see the data in a workbook.

  15. #15
    Registered User
    Join Date
    06-05-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Delete Columns where Row 1 is not equal to X or Y

    Okay, Let me remove the PCI data

  16. #16
    Registered User
    Join Date
    06-05-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Delete Columns where Row 1 is not equal to X or Y

    i2 Notebook no PCI.xlsm

    See if this attachment works.

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,675

    Re: Delete Columns where Row 1 is not equal to X or Y

    Quote Originally Posted by dhpeter83 View Post
    Find
    "Token" in column, apply number format

    Find Date in columns, apply date format...make sense?
    I don't find any date column.

    Is this a general question or related to your original question?
    If not related, you will need to open a new thread since forum rule allows only one question per thread.

  18. #18
    Registered User
    Join Date
    06-05-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Delete Columns where Row 1 is not equal to X or Y

    Quote Originally Posted by jindon View Post
    I don't find any date column.

    Is this a general question or related to your original question?
    If not related, you will need to open a new thread since forum rule allows only one question per thread.
    There is a "Trans Date" Column where the data is further down, and in a 24 hour time format.

    It's relevant to this question because it's the same project, though a different task i guess. I can open a separate thread.

    I'll call it

    Macro to find columns and format

+ 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. Delete row if some columns equal others. HELP
    By lmvmbc in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-24-2013, 01:42 PM
  2. Delete row if some columns equal others
    By lmvmbc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2013, 11:14 PM
  3. Help!! How to delete rows based on value on 2 columns(same equal=0)
    By giallorossi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2013, 03:19 AM
  4. Replies: 2
    Last Post: 01-14-2009, 04:01 AM
  5. Comparing data in columns and delete if not equal
    By Robert in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-04-2005, 04:06 PM

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