Results 1 to 17 of 17

Amending macro code - Deleting and moving columns

Threaded View

  1. #1
    Forum Contributor
    Join Date
    03-05-2015
    Location
    Playa Del Carmen, Mexico
    MS-Off Ver
    2016
    Posts
    111

    Amending macro code - Deleting and moving columns

    I have the following code that deletes a lot of columns, copy and pastes one into column B and then sorts by column B.

    Sub test()
    Dim ws As Worksheet, lr As Long
    Set ws = ActiveSheet
    lr = ws.UsedRange.Rows.Count
    With ws
        .Range("C:D,K:O,R:V,X:AK,AM:AO").EntireColumn.Delete
        .Range("B:B").Insert Shift:=xlToRight
        .Range("J:J").Cut Destination:=.Range("B:B")
        .Range("J:J").Delete
        .Range("A" & lr).EntireRow.Delete
        For x = lr To 2 Step -1
            If Left(.Range("B" & x), 2) <> "29" Then .Range("A" & x).EntireRow.Delete
        Next
    End With
    End Sub

    I now need to include the previously deleted columns M & O and changed the code to show this....
        .Range("C:D,K:L,R:V,X:AK,AM:AO").EntireColumn.Delete
    .... and this also changed the column I needed to cut and paste to K....

       .Range("B:B").Insert Shift:=xlToRight
        .Range("K:K").Cut Destination:=.Range("B:B")
        .Range("K:K").Delete
    ... but it isn't working. I do not understand the rest of the code as I didn't create it. The macro simply deletes all records !

    Can anyone please help ?
    Attached Files Attached Files
    Last edited by M12NIX; 12-08-2015 at 11:09 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Amending Macro Code - Deleting & Moving Columns
    By M12NIX in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-09-2015, 03:03 AM
  2. Create VBS code for deleting (moving) row content to new table in separte sheet
    By saslotteroy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-13-2015, 04:31 AM
  3. Code/Macro for deleting empty columns and rows.
    By gautamacharya in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-09-2014, 01:49 PM
  4. Replies: 3
    Last Post: 09-14-2013, 02:22 AM
  5. [SOLVED] auto Deleting contents of certain columns when moving rows between sheets with one click
    By R.Sloan in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 04-18-2013, 04:57 AM
  6. Deleting and moving certain columns of cells from one sheet to another.
    By m0aje in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-22-2012, 11:52 AM
  7. Deleting contents and moving columns
    By tessda in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 07-07-2009, 05:26 PM

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