+ Reply to Thread
Results 1 to 11 of 11

Delete columns

  1. #1
    Registered User
    Join Date
    01-23-2013
    Location
    Cornwall
    MS-Off Ver
    Excel 2003
    Posts
    30

    Delete columns

    My macro below as can be seen when a condition is achieved ('ongoing' is typed in the master work sheet) in a column that line of data is moved into a work sheet called ONGOING.
    When the word 'complete is typed into the master work sheet the data on that line is moved into a work sheet called 'COMPLETE' and that line that was in the ONGOING sheet is deleted.
    Works perfectly as is but..
    I want to remove columns in the master sheet ie move the 'Status' column that registers ongoing or complete from column 'X' to column 'U'.
    So I adjusted the macro accordingly.
    Works perfectly with the exception the 'ONGOING' sheet doesn't annotated that is the 'foundCase.EntireRow.Delete' function doesn't work.
    Can some one tell me what else in the code needs adjusting please.
    Fred







    Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("X:X")) Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
    Dim bottomH As Long
    Dim bottomC As Long
    Dim rng As Range
    Dim foundCase As Range
    If Target = "ongoing" Then
    bottomC = Sheets("ONGOING").Range("C" & Rows.Count).End(xlUp).Row
    Set foundCase = Sheets("ONGOING").Range("C2:C" & bottomC).Find(Target.Offset(0, -16), LookIn:=xlValues, LookAt:=xlWhole)
    If Not foundCase Is Nothing Then
    'Target.EntireRow.Copy Sheets("ONGOING").Range("A" & foundCase.Row)
    Range("A" & Target.Row).Copy Sheets("ONGOING").Range("A" & foundCase.Row)
    Range("G" & Target.Row & ":I" & Target.Row).Copy Sheets("ONGOING").Range("B" & foundCase.Row)
    Range("J" & Target.Row & ":K" & Target.Row).Copy Sheets("ONGOING").Range("E" & foundCase.Row)
    Range("S" & Target.Row).Copy Sheets("ONGOING").Range("G" & foundCase.Row)
    'Range("V" & Target.Row).Copy Sheets("ONGOING").Range("G" & foundCase.Row)'
    Range("X" & Target.Row).Copy Sheets("ONGOING").Range("H" & foundCase.Row)
    Else
    Range("A" & Target.Row).Copy Sheets("ONGOING").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
    Range("G" & Target.Row & ":I" & Target.Row).Copy Sheets("ONGOING").Cells(Rows.Count, "B").End(xlUp).Offset(1, 0)
    Range("J" & Target.Row & ":K" & Target.Row).Copy Sheets("ONGOING").Cells(Rows.Count, "E").End(xlUp).Offset(1, 0)
    Range("S" & Target.Row).Copy Sheets("ONGOING").Cells(Rows.Count, "G").End(xlUp).Offset(1, 0)
    'Range("V" & Target.Row).Copy Sheets("ONGOING").Cells(Rows.Count, "G").End(xlUp).Offset(1, 0)'
    Range("X" & Target.Row).Copy Sheets("ONGOING").Cells(Rows.Count, "H").End(xlUp).Offset(1, 0)
    End If
    ElseIf Target = "complete" Then
    bottomH = Sheets("COMPLETE").Range("H" & Rows.Count).End(xlUp).Row
    Set foundCase = Sheets("COMPLETE").Range("H2:H" & bottomH).Find(Target.Offset(0, -16), LookIn:=xlValues, LookAt:=xlWhole)
    If Not foundCase Is Nothing Then
    Target.EntireRow.Copy Sheets("COMPLETE").Range("A" & foundCase.Row)
    Else
    Target.EntireRow.Copy Sheets("COMPLETE").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
    End If
    bottomC = Sheets("ONGOING").Range("C" & Rows.Count).End(xlUp).Row
    Set foundCase = Sheets("ONGOING").Range("C2:C" & bottomC).Find(Target.Offset(0, -16), LookIn:=xlValues, LookAt:=xlWhole)
    If Not foundCase Is Nothing Then
    foundCase.EntireRow.Delete
    End If
    End If
    End Sub

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,486

    Re: Delete columns

    Hello,

    Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,486

    Re: Delete columns

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  4. #4
    Registered User
    Join Date
    01-23-2013
    Location
    Cornwall
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Delete columns

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-23-2013
    Location
    Cornwall
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Delete columns

    I think I have attached !!
    Fred
    Attached Files Attached Files

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,486

    Re: Delete columns

    Your code provided and your sample workbook, does not show what you are explaining in your 1st post.

    You need to change your Target column to U:U and your offsets will be -13 won't they.

  7. #7
    Registered User
    Join Date
    01-23-2013
    Location
    Cornwall
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Delete columns

    Yes correct U:U is what I am trying to achieve I understand that I had changed it so but......The delete action didn't delete.
    I didn't adjust the offset I left it at -16 I will change and try again.
    Thanks

    Can you explain the offset statement please, whats it offsetting?
    Thanks again
    Fred

  8. #8
    Registered User
    Join Date
    01-23-2013
    Location
    Cornwall
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Delete columns

    Tried that it works perfectly.
    Thanks very much can you explain the offset rule.
    Whats it offsetting from what
    Fred

  9. #9
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,486

    Re: Delete columns

    Basically,
    The -13 is 13 cells from the left of target cell, 13 would be 13 cells from the right of target cell.
    Select a cell in column U. Then press the left arrow key 13 times.

  10. #10
    Registered User
    Join Date
    01-23-2013
    Location
    Cornwall
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Delete columns

    OK understand what you say but if you count 13 cells to the left of the target cell it comes in the middle of the row !
    Whats that got to do with any thing? What are we trying to achieve by putting in a 13 cell offset?
    Fred

  11. #11
    Registered User
    Join Date
    01-23-2013
    Location
    Cornwall
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Delete columns

    OK see where we are coming from now its the 13th cell off set to the left that makes it the cell the target needs to be in the new sheet.
    Duhhhh
    Fred

+ 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 1 to 8 rows. Do text to columns to specific columns.
    By niceblue in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-06-2013, 10:53 AM
  2. 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
  3. Delete all blank columns !!!DELETE!!! [*DUPLICATE*]
    By Storm08 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-25-2012, 05:26 AM
  4. Delete & Merge Columns,Delete Rows with filter, etc
    By traderindia in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-17-2009, 02:12 AM
  5. Delete multiple columns by column name no criteria need, just delete them
    By duugg in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-24-2009, 10:40 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