+ Reply to Thread
Results 1 to 3 of 3

Move data in rows ignoring blanks

Hybrid View

  1. #1
    Registered User
    Join Date
    03-24-2010
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    6

    Move data in rows ignoring blanks

    Hi everyone,

    I'm looking for a macro to remove the blanks between two set of data in every single row.

    It's always two cells with data in every row, but the first data in the row should be fixed.

    For example, in row 2 of the attached file, I have data in column A and column G, I want to move the data of column G to column B. But in row 3 the data si in column B and I, so I want to move it to column C, and so on.

    Thank you in advance for your help. Move between rows.xlsx

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Move data in rows ignoring blanks

    mmartin79,

    Welcome to the forum!
    Give this a try:
    Sub tgr()
        
        Dim rngDel As Range
        Dim rngGap As Range
        Dim rIndex As Long
        Dim strAddress As String
        
        On Error Resume Next
        For rIndex = 2 To Cells.Find("*", Range("A1"), xlValues, , , xlPrevious).Row
            strAddress = Split(Rows(rIndex).SpecialCells(xlCellTypeConstants).Address, ",")(1)
            If Len(strAddress) > 0 Then
                Set rngGap = Range(Range(strAddress).End(xlToLeft).Offset(, 1), Range(strAddress).Cells(1).Offset(, -1))
                If rngDel Is Nothing Then
                    Set rngDel = rngGap
                Else
                    Set rngDel = Union(rngDel, rngGap)
                End If
                Set rngGap = Nothing
                strAddress = vbNullString
            End If
        Next rIndex
        On Error GoTo 0
        
        If Not rngDel Is Nothing Then
            rngDel.Delete xlToLeft
            Set rngDel = Nothing
        End If
        
    End Sub
    Last edited by tigeravatar; 06-22-2012 at 06:42 PM.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    03-24-2010
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Move data in rows ignoring blanks

    Thanks tigeravatar, works great!

+ 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