+ Reply to Thread
Results 1 to 7 of 7

Thread: Delete merged rows

  1. #1
    Forum Contributor
    Join Date
    02-07-2011
    Location
    Bhutan
    MS-Off Ver
    Excel 2007
    Posts
    168

    Delete merged rows

    Hi,
    I am stuch with this problem,What I want is a VBA code against the button "Delete" in the sheet "Metal" that,
    if in the sheet "Face" the value in the column AL is 0 then the entire row will be deleted in the "Metal" sheet.
    The values in Column J in "Face" and Column F in the sheet "Metal" is unique.That is Test1,Test2,Test3 etc..
    I am uploading a dummy sheet for reference.
    Thanks in advance.
    Attached Files Attached Files
    Last edited by fatalcore; 02-14-2012 at 04:41 AM.

  2. #2
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,385

    Re: Delete merged rows

    So should the values in column J in "Face" and column F in "Metal" be matched and then the value in column AL checked and then the corresponding row in Sheet Metal to be deleted?
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Contributor
    Join Date
    02-07-2011
    Location
    Bhutan
    MS-Off Ver
    Excel 2007
    Posts
    168

    Re: Delete merged rows

    Hi arlu1201,
    Yes, you are absolutely right about it. If the value in AL = 0 then only the row in Sheet "Metal" will be deleted.
    Thanks in advance.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Delete merged rows

    Hello fatalcore,

    Here is the code for the two macros that appear in the attached workbook.

    Command Button Code
    Private Sub CommandButton2_Click()
    
        Dim Cell As Range
        Dim Rng As Range
        
            Set Rng = Worksheets("Face").Range("AL20, AL22, AL24")
            
            Application.ScreenUpdating = False
            
                For Each Cell In Rng
                    If Cell = 0 Then
                       Call FindThenDeleteRow(Rng.Parent.Cells(Cell.Row, "J").Text)
                    End If
                Next Cell
            
           Application.ScreenUpdating = True
           
    End Sub

    Module1 Code to Delete the Rows
    
    Sub FindThenDeleteRow(ByVal Text As String)
    
        Dim Cell As Range
        Dim Rng As Range
        
            Set Rng = Worksheets("Metal").Range("E9").CurrentRegion
            
            Set Cell = Rng.Find("test2", , xlValues, xlWhole, xlByRows, xlNext, False)
            If Not Cell Is Nothing Then
               Cell.MergeArea.EntireRow.Delete
            End If
            
    End Sub
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Forum Contributor
    Join Date
    02-07-2011
    Location
    Bhutan
    MS-Off Ver
    Excel 2007
    Posts
    168

    Re: Delete merged rows

    Hi,Leith Ross

    Thanks for your reply, can u please modify the code a little bit so that the range is not fixed like test2 only. I want it for Test1, Test2 and Test3 also.
    Thanks in advance.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Delete merged rows

    Hello fatalcore,

    Sorry, I forgot to remove "test2" from the Find operation. The value to find is passed in as as string. The code should be as below...
    Sub FindThenDeleteRow(ByVal Text As String)
    
        Dim Cell As Range
        Dim Rng As Range
        
            Set Rng = Worksheets("Metal").Range("E9").CurrentRegion
            
            Set Cell = Rng.Find(Text, , xlValues, xlWhole, xlByRows, xlNext, False)
            If Not Cell Is Nothing Then
               Cell.MergeArea.EntireRow.Delete
            End If
            
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  7. #7
    Forum Contributor
    Join Date
    02-07-2011
    Location
    Bhutan
    MS-Off Ver
    Excel 2007
    Posts
    168

    Re: Delete merged rows

    Thanks mate

+ 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.2.0