Move Data from one Column to another

Anonymous
2023-12-22T03:52:26+00:00

I have this sheet that a vendor sends me with commissions and credit memos. They put the commissions in one set of columns, and the credit memos in another set of columns.. I need to format the sheet so it can be imported into the sales system I use. Can anyone out there help me with some VBA code to go through this sheet and if there is data in the credit memo columns, just move it to the invoice columns?

Below is s a simple sample...but the sheet has 1000's of rows

Any help would be greatly appreciated.

Here is the sample file...Sample File

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. Anonymous
    2023-12-23T05:24:29+00:00

    Try this one.

    ====================

    Sub MoveColumns()

    Dim lastRow As Long 
    
    lastRow = Cells(Rows.Count, "F").End(xlUp).Row 
    
    For i = 5 To lastRow 
    
        If Cells(i, "F").Value < 0 Then 
    
            Cells(i, "I").Value = Cells(i, "D").Value 
    
            Cells(i, "J").Value = Cells(i, "E").Value 
    
            Cells(i, "K").Value = Cells(i, "E").Value 
    
            Cells(i, "E").ClearContents 
    
            Cells(i, "L").Value = Cells(i, "F").Value 
    
            Cells(i, "F").ClearContents 
    
            Cells(i, "M").Value = Cells(i, "G").Value 
    
            Cells(i, "G").ClearContents 
    
            Cells(i, "N").Value = Cells(i, "H").Value 
    
            Cells(i, "H").ClearContents 
    
        End If 
    
    Next i 
    

    End Sub

    ====================

    Result:

    0 comments No comments