+ Reply to Thread
Results 1 to 8 of 8

delete cols in vba

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    delete cols in vba

    i have this code to delete rows in vba

    Please Login or Register  to view this content.

    Is there a similar code to delete cols.......i tried this but seem to get an error

    Please Login or Register  to view this content.
    Last edited by welchs101; 06-08-2011 at 06:43 PM.

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: delete cols in vba

    How about...

    Please Login or Register  to view this content.
    If you turn on the macro recorder it will give you the syntax.
    HTH
    Regards, Jeff

  3. #3
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: delete cols in vba

    that works..........the reason i was trying to do it the other way (with #s instead of letters) is because i have a value which is equal to the number of cols to delete........so i was hoping i could use numbers.

    thanks. if i cant find what i am looking for i am going to use your suggestion.

    thanks.

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: delete cols in vba

    A very good question I probably don't know the right answer for.

    The only thing that strikes me right now is to run something like this, but not sure if I'm barking up the right tree.

    Are these columns always going to be next to each other? With this code, if it was column 1 and 2 you want deleted then column 1 would delete first making the old column 2 now column 1 and the for next would run twice.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: delete cols in vba

    If you want to use numbers you could use code like

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  6. #6
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: delete cols in vba

    Hi Mike,

    Thanks for the help...sure do appreciate it.

    I tried the .Resize method and it didn't work for me, but I see why now.

    Any reason why the .Resize works this way...

    Please Login or Register  to view this content.
    But not...

    Please Login or Register  to view this content.

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: delete cols in vba

    No, I don't know why the compiler interprets the omitted argument differently than a 0.
    (The Worksheet function INDEX does interpret no argument as 0)

  8. #8
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: delete cols in vba

    Okay got it...thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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