+ Reply to Thread
Results 1 to 4 of 4

Delete every 2nd column from fixed starting point

  1. #1
    Darin Kramer
    Guest

    Delete every 2nd column from fixed starting point

    Howdie,
    Can anyone help with VB to do the following: I would like to delete
    columns F and G, then skip H and I, delete j and k, skip l and m, delete
    n and o etc

    So basically starting at F delete two columns, skip two columns, delete
    two columns etc until no more data in the columns...

    Thanks guys, appreciate your help

    Regards

    D



    *** Sent via Developersdex http://www.developersdex.com ***

  2. #2
    Bob Phillips
    Guest

    Re: Delete every 2nd column from fixed starting point

    For i = 26 To 6 Step -4
    Columns(i).Resize(, 2).Delete
    Next i

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "Darin Kramer" <darin_kramer@hotmail.com> wrote in message
    news:eRCW3fLXGHA.1192@TK2MSFTNGP03.phx.gbl...
    > Howdie,
    > Can anyone help with VB to do the following: I would like to delete
    > columns F and G, then skip H and I, delete j and k, skip l and m, delete
    > n and o etc
    >
    > So basically starting at F delete two columns, skip two columns, delete
    > two columns etc until no more data in the columns...
    >
    > Thanks guys, appreciate your help
    >
    > Regards
    >
    > D
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***




  3. #3
    Edwin Tam
    Guest

    RE: Delete every 2nd column from fixed starting point

    Interesting mathematics question. :> You should delete from the right to left
    instead of from left to right. (in fact, always do this.)

    Try the macro below. It should work no matter how many columns you've got in
    the worksheet. Also, it assumes data starts in column A.

    Sub go_delete()
    Dim tmp as Integer
    Dim tmp2 as Integer
    Dim tmp_address As String, row_count As Single

    With ActiveSheet.UsedRange
    tmp = Fix((.Columns.Count - 5) / 4)
    If (.Columns.Count - 5) Mod 4 > 0 Then
    tmp = tmp + 1
    End If
    tmp_address = .Address(False, False)
    row_count = .Rows.Count
    End With
    With ActiveSheet.Range(tmp_address)
    With .Offset(0, 5).Resize(row_count, .Columns.Count - 5)
    For tmp2 = tmp To 1 Step -1
    With .Columns(4 * tmp2 - 3)
    .Resize(row_count, 2).EntireColumn.Delete
    End With
    Next
    End With
    End With
    End Sub

    Regards,
    Edwin Tam
    edwintam@vonixx.com
    http://www.vonixx.com



    "Darin Kramer" wrote:

    > Howdie,
    > Can anyone help with VB to do the following: I would like to delete
    > columns F and G, then skip H and I, delete j and k, skip l and m, delete
    > n and o etc
    >
    > So basically starting at F delete two columns, skip two columns, delete
    > two columns etc until no more data in the columns...
    >
    > Thanks guys, appreciate your help
    >
    > Regards
    >
    > D
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    >


  4. #4
    Darin Kramer
    Guest

    RE: Delete every 2nd column from fixed starting point


    Thanks Edwin,

    It works perfectly!!!

    REgards

    Darin


    *** Sent via Developersdex http://www.developersdex.com ***

+ 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