+ Reply to Thread
Results 1 to 17 of 17

Remove Columns, Cut and Paste Column, Delete Rows - Macros

  1. #1
    Forum Contributor
    Join Date
    03-05-2015
    Location
    London, England
    MS-Off Ver
    2024
    Posts
    124

    Remove Columns, Cut and Paste Column, Delete Rows - Macros

    I've been asked by work, after claiming I'm pretty good with Excel to provide a short cut for the team. I thought it'd be pretty straight forward but after six years out of the I.T game, and never really being very good at VBA, I'm struggling. Please somebody help !!!

    A report is exported daily that requires manipulation. A number of columns require deleting, one needs to be cut and pasted and then many of the records deleted. As most of the employees are not users of Excel I need to make this as easy as possible for them.

    Firstly I need to delete the following columns which I have the code for (I think)

    Sub sbVBS_To_Delete_Specific_Multiple_Columns()
    Sheets("Sheet1").Range("C:D,K:O,R:V,X:AK,AM:AO").EntireColumn.Delete
    End Sub

    Then I need to Cut column I (Cuarto) to column B.

    Then I need to delete all rows that do not have the room number (Cuarto) starting with 29**. Some cells are blank. Others are room numbers ranging from 101 to 5538.

    Finally the last row of the report needs to go. This is never in the same row number but is always the last row.


    Any help would be greatly appreciated. I will add attachments of the actual report when it works.

    Is this all possible in one macro ?
    Last edited by M12NIX; 11-12-2015 at 06:58 PM. Reason: Cannot add attachments

  2. #2
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Remove Columns, Cut and Paste Column, Delete Rows - Macros

    change the red A to the column where is the room

    Please Login or Register  to view this content.
    Kind regards
    Leo

  3. #3
    Forum Contributor
    Join Date
    03-05-2015
    Location
    London, England
    MS-Off Ver
    2024
    Posts
    124

    Re: Remove Columns, Cut and Paste Column, Delete Rows - Macros

    Thanks Leo. Almost there. The columns are exactly where I need them but all of the columns are blank.

  4. #4
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Remove Columns, Cut and Paste Column, Delete Rows - Macros

    think this is the reasen

    Then I need to delete all rows that do not have the room number (Cuarto) starting with 29**. Some cells are blank. Others are room numbers ranging from 101 to 5538.

    this part of the code removes the rowes

    Please Login or Register  to view this content.
    Kind regards
    Leo

  5. #5
    Forum Contributor
    Join Date
    03-05-2015
    Location
    London, England
    MS-Off Ver
    2024
    Posts
    124

    Re: Remove Columns, Cut and Paste Column, Delete Rows - Macros

    Every row has been removed. There are no records. The room numbers go from 2901 - 2934. I just need those starting with 29**

  6. #6
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Remove Columns, Cut and Paste Column, Delete Rows - Macros

    in witch column the room numbers are ?

  7. #7
    Forum Contributor
    Join Date
    03-05-2015
    Location
    London, England
    MS-Off Ver
    2024
    Posts
    124

    Re: Remove Columns, Cut and Paste Column, Delete Rows - Macros

    B. (After being switched from I) Thanks for this Leo.

  8. #8
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Remove Columns, Cut and Paste Column, Delete Rows - Macros

    So change this part

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    Kind regards
    Leo

  9. #9
    Forum Contributor
    Join Date
    03-05-2015
    Location
    London, England
    MS-Off Ver
    2024
    Posts
    124

    Re: Remove Columns, Cut and Paste Column, Delete Rows - Macros

    I wish I could do this. Thank you so very much Leo. Is there any way to ensure that 3 digit numbers are excluded also. If I change the 29 to 31 I get the 31** room numbers but I also get the three digit numbers such as 310 but I do not want these.

  10. #10
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Remove Columns, Cut and Paste Column, Delete Rows - Macros

    you have to be more specific, cause room 310 is normaliter in 31**


    this part looks @ first 2 characters in column B, you can change the 2 to more characters if you want
    Please Login or Register  to view this content.
    kind regards
    Leo

  11. #11
    Forum Contributor
    Join Date
    03-05-2015
    Location
    London, England
    MS-Off Ver
    2024
    Posts
    124

    Re: Remove Columns, Cut and Paste Column, Delete Rows - Macros

    Thank you kind Sir. Thank you so very much.

  12. #12
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Remove Columns, Cut and Paste Column, Delete Rows - Macros

    maybe

    Please Login or Register  to view this content.
    if not, poste the expected result in excel sheet

    Kind regards
    Leo

  13. #13
    Forum Contributor
    Join Date
    03-05-2015
    Location
    London, England
    MS-Off Ver
    2024
    Posts
    124

    Re: Remove Columns, Cut and Paste Column, Delete Rows - Macros

    Hi Leo. I've just notice that when moving the column from I to B it has replaced the data rather than inserting a new column. Is there a way to do this ?

  14. #14
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Remove Columns, Cut and Paste Column, Delete Rows - Macros

    Like this ?

    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    03-05-2015
    Location
    London, England
    MS-Off Ver
    2024
    Posts
    124

    Re: Remove Columns, Cut and Paste Column, Delete Rows - Macros

    Spot on. I cannot thank you enough. Have a good day.

  16. #16
    Forum Contributor
    Join Date
    03-05-2015
    Location
    London, England
    MS-Off Ver
    2024
    Posts
    124

    Re: Remove Columns, Cut and Paste Column, Delete Rows - Macros

    Hey Leo, I'm sorry to pester but I'm at a loss. I need to keep an additional two columns in the report (M & O) and I changed the code below. What am I missing as this isn't working ?!

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

  17. #17
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Remove Columns, Cut and Paste Column, Delete Rows - Macros

    this part

    Please Login or Register  to view this content.
    think has to be

    Please Login or Register  to view this content.
    Kind regards
    Leo

+ 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. How to create Macros buttons to add or delete columns and rows.
    By damienchew in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-22-2014, 08:39 PM
  2. Replies: 2
    Last Post: 01-13-2014, 10:52 AM
  3. Copy columns, remove duplicates and paste different worksheet and column query
    By Chris* in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-13-2014, 06:52 AM
  4. [SOLVED] Remove rows based on duplicates in certain columns, and merge data from another column
    By yanagi600 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 01-02-2013, 04:17 PM
  5. Macro to delete certain columns and delete rows based on time in another column
    By beepbeep27 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-12-2012, 11:47 AM
  6. how to remove the blank column (delete rows)
    By SelinaT in forum Excel General
    Replies: 1
    Last Post: 04-18-2011, 03:50 AM

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