+ Reply to Thread
Results 1 to 9 of 9

Delete Columns If any contain values

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-28-2012
    Location
    nz
    MS-Off Ver
    Excel 2010
    Posts
    125

    Lightbulb Delete Columns If any contain values

    Hi

    Have code that deletes after Column C and variable column ?

    (Its for a Dynamic Graph, columns are inserted every minute)

    Would be great if it would now only delete those in between columns if there are values in- between Column C and ?

    So if there are no values in the in between columns do nothing, if Called.

    Hope someone can help

    Thanks in advance

    Mike
    Attached Files Attached Files
    Last edited by keen2xl; 10-07-2013 at 08:14 PM.

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Delete Columns If any contain values

    Hello keen2xl,

    Much easier way would be to ClearContents of the whole range.i.e.:

    In a Standard Module;

    Sub CleanoutRws()
    ActiveSheet.Columns("A:i").ClearContents
    End Sub
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Forum Contributor
    Join Date
    08-28-2012
    Location
    nz
    MS-Off Ver
    Excel 2010
    Posts
    125

    Re: Delete Columns If any contain values

    Hi Winon

    Thanks for reply

    I messed up first post a bit i think, so edited a tad to hopefully make more sense and included macro that deletes columns from "C" to ? in attached file thought it was in there first time, I'm a twit

    Sorry about that.

    So actually do need columns Deleted but only if there is Values in inserted columns, thing is it at the moment if it is "called" the way things are set up on my main spread sheet, it deletes the end Blue Column when there is nothing inserted between C and the Blue Column.

    I need Blue column always for the Dynamic Graph to work it is part of it.

    Hope makes Sense hope file now helps

    Thanks again

    Mike.

  4. #4
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Delete Columns If any contain values

    Hello keen2xl,

    Could you upload a sample file for us to look at?

  5. #5
    Forum Contributor
    Join Date
    08-28-2012
    Location
    nz
    MS-Off Ver
    Excel 2010
    Posts
    125

    Re: Delete Columns If any contain values

    Hi Winon

    Should be a file top of post "Copy of Delete Columns if Values.xlsm"‎ replaced first one you may have the first one.

    I was born to confuse : )

    Cheers

    If not i'll try again

    Mike

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Delete Columns If any contain values

    From your sample file I gather it is only Column A to be cleared. Is that correct?

  7. #7
    Forum Contributor
    Join Date
    08-28-2012
    Location
    nz
    MS-Off Ver
    Excel 2010
    Posts
    125

    Cool Re: Delete Columns If any contain values

    Hi Winon

    Hi

    You just Solved it for me, I didn't realise in the code that if i adjust the fist number





    Sub DeleDynamicGraphCols()

    Application.ScreenUpdating = False

    With Cells(1, Columns.Count).End(xlToLeft)
    If .Column > 35 Then
    Range(Cells(1, 35), .Offset(0, -1).Address).EntireColumn.Delete
    End If
    End With

    Application.ScreenUpdating = True

    End Sub





    to the same column as the one i want remaining, it won't delete any past there "Offset -1"

    After i went in to try and re create things for screen shots for you, as my actual spread sheet is set up different. Ha

    Thanks Mate

    Interaction helps

    Solved

    Mike. learning Vba slowly (Very)

  8. #8
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Delete Columns If any contain values

    Hello keen2xl,

    No need to clear the numbers from Column C. As for the rest everything seems to be fine. You may insert as many Columns as you like and hit the "Delete Button bottom left, and the Blue column will restore to its original position. Numers wil be Cleared from Column A, and when you click on the reset Button at the top of Column B, Numbers and formulas in Column A will be restored.

    I think it is pretty much what you wanted.
    Attached Files Attached Files
    Last edited by Winon; 10-08-2013 at 02:04 AM. Reason: Spelling

  9. #9
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Delete Columns If any contain values

    Hi keen2xl,

    You are welcome.

    Glad I could help.

    As a matter of fact, I got so absorbed with your issue that I never went to bed last night, and now my dear little Evil Spirit is on my case. Man, is she livid.LOL.

    Thank you for adding to my Reputation.

    Please remember to Wrap any code that you post according to the Forum Rules.

    Regards
    Last edited by Winon; 10-08-2013 at 02:41 AM. Reason: Reminder to wrap code

+ 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 values of duplicate rows only in specific columns
    By DeeBee in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-18-2013, 09:43 AM
  2. [SOLVED] Looking for VBA code to delete rows if values in 3 specific columns are the same
    By Priceman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-02-2012, 10:32 AM
  3. Macro to Delete Values if in both columns
    By Enemee in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-15-2011, 08:10 AM
  4. Compare 2 columns delete rows with matching values
    By mattmac in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-05-2009, 01:50 PM
  5. Compare two columns and delete founded values
    By Oleg in forum Excel General
    Replies: 0
    Last Post: 09-28-2006, 09:50 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