+ Reply to Thread
Results 1 to 6 of 6

Define range and then unmerge/edit range

Hybrid View

bruizer31 Define range and then... 06-01-2013, 03:17 PM
TMS Re: Define range and then... 06-01-2013, 03:28 PM
bruizer31 Re: Define range and then... 06-01-2013, 03:35 PM
TMS Re: Define range and then... 06-01-2013, 05:55 PM
bruizer31 Re: Define range and then... 06-02-2013, 05:43 PM
TMS Re: Define range and then... 06-02-2013, 06:02 PM
  1. #1
    Registered User
    Join Date
    05-14-2013
    Location
    California
    MS-Off Ver
    Excel 2013
    Posts
    78

    Define range and then unmerge/edit range

    Hi all,

    I'm not sure how to write the syntax for a little bit of code i am trying to complete.

    Im not sure how to name a range that is ("A7:N"&lastrow),
    and then go through that range and:
    -unmerge all cells within the range
    -Look in column C and if it is blank then clear the column N value in the same row.
    -look in column A and if it is blank delete the entire row.

    I already have the variable lastrow defined so no need to define it in your replies

    Thanks for your help I've been trying to get this part for a while.
    Last edited by bruizer31; 06-01-2013 at 03:19 PM. Reason: adding info

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,135

    Re: Define range and then unmerge/edit range

    Range("A7:N" & Lastrow).Cells.UnMerge

    and

    Dim Cell as Range
    For Each Cell In Range("A7:A" & Lastrow)
       ' do whatever
       If Cell.Offset(0,2).Value = "" Then
               Cell.Offset(0, 13).Value = ""
       End If
    Next 'Cell

    Regards, TMS
    Last edited by TMS; 06-01-2013 at 05:42 PM. Reason: Edit to code, second part
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    05-14-2013
    Location
    California
    MS-Off Ver
    Excel 2013
    Posts
    78

    Re: Define range and then unmerge/edit range

    Thank you, How do i include deleting the entire row if there is no value in column A within that range?

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,135

    Re: Define range and then unmerge/edit range

    OK, try this, all the requirements in one subroutine.

    Sub sDoStuff()
    
    Dim LastRow As Long
    Dim Cell As Range
    Dim rRngToDelete As Range
    
    LastRow = Cells.SpecialCells(xlCellTypeLastCell).Row
    
    ' unmerge cells in range
    Range("A7:N" & LastRow).Cells.UnMerge
    
    For Each Cell In Range("A7:A" & LastRow)
        ' build range to delete
        If Cell.Value = "" Then
            If rRngToDelete Is Nothing Then
                Set rRngToDelete = Cell
            Else
                Set rRngToDelete = Union(rRngToDelete, Cell)
            End If
        End If
        
        ' clear column N if column C is blank
        If Cell.Offset(0, 2).Value = "" Then
            Cell.Offset(0, 13).Value = ""
        End If
    Next 'Cell
    
    ' delete cells if appropriate
    If Not rRngToDelete Is Nothing Then
        rRngToDelete.EntireRow.Delete
    End If
    
    End Sub


    Regards, TMS

  5. #5
    Registered User
    Join Date
    05-14-2013
    Location
    California
    MS-Off Ver
    Excel 2013
    Posts
    78

    Re: Define range and then unmerge/edit range

    Thanks for your help, that worked perfectly!

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,135

    Re: Define range and then unmerge/edit range

    You're welcome. Thanks for the rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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