Excel Move Cells to Right.

Solved/Closed
j3kj3k Posts 15 Registration date Tuesday 1 June 2010 Status Member Last seen 11 July 2012 - 15 Jun 2010 à 17:25
j3kj3k Posts 15 Registration date Tuesday 1 June 2010 Status Member Last seen 11 July 2012 - 17 Jun 2010 à 12:04
Hello,

I have a task to move several cells in a few column to the far right column (like below)
Number of column can be up to 25.

Your help will be greatly appreciated.

http://www.editgrid.com/user/j3kj3k/ExcelQuestion
Related:

2 responses

rizvisa1 Posts 4478 Registration date Thursday 28 January 2010 Status Contributor Last seen 5 May 2022 766
16 Jun 2010 à 20:20
Try this

Sub MoveData()
Dim lRow As Long
Dim iMaxCol As Integer
Dim lMaxRow As Long
Dim iCol As Integer
Dim Cell As Range
Dim sValue As Variant

    iMaxCol = Cells(1, Columns.Count).End(xlToLeft).Column
    
    Set Cell = Cells.Find("*", Cells(1, 1), SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
    
    If Cell Is Nothing Then Exit Sub
    
    For lRow = 2 To Cell.Row
    
        For iCol = iMaxCol To 2 Step -1
            
            If Cells(lRow, iCol) = "" Then
                sValue = Cells(lRow, iCol).End(xlToLeft)
                Cells(lRow, iCol).End(xlToLeft) = ""
                Cells(lRow, iCol) = sValue
            End If
            
        
        Next iCol
  
  Next lRow

    
End Sub
j3kj3k Posts 15 Registration date Tuesday 1 June 2010 Status Member Last seen 11 July 2012
17 Jun 2010 à 12:04
Many Thanks !!!!
rizvisa1 Posts 4478 Registration date Thursday 28 January 2010 Status Contributor Last seen 5 May 2022 766
15 Jun 2010 à 19:52
On what basis would column shift. In your example some did and some did not.
j3kj3k Posts 15 Registration date Tuesday 1 June 2010 Status Member Last seen 11 July 2012
16 Jun 2010 à 13:21
Hi, Rizvisa1

That was my bad. I have updated the spread sheet. Basically move all none balck cell next to last column (not concatenate).

Thanks