Solved

# VBA to find and move

Posted on 2016-08-12
55 Views
Can an expert help me out with this please. I have attached a file that should make it clear.

Check Col ‘V’ for any amounts other than zero.

If there is an amount select the cell below the amount then insert a new row
Move the amount from ‘V’ and put into the cell below in ‘U’
Move the data from ‘R’ and put into the cell below in ‘Q’
Copy the data in ‘P’ and put in cell below.

Repeat for any other amounts.

then

Check Col ‘W’ for anything other than zero’s
Select the cell below the amount then insert a 2 new rows
Copy the amount and put into the new row in ‘U’ as a minus.
Copy the data in P,Q and put in line below
Now select the original amount and move it under the minus amount [as a plus]

Move the data from ‘R’ and put that in the ‘Q’ [2 lines below]
Copy the data from P in the original row and put into ‘P’ in the blank cell.

Repeat for any other amounts.
Find-and-Move.xlsx
0
Question by:Jagwarman
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 31

Accepted Solution

Subodh Tiwari (Neeraj) earned 500 total points
ID: 41753472
Try something like this......

``````Sub ReArrangeData()
Dim Rng As Range, Cell As Range
Dim lr As Long, i As Long

Application.ScreenUpdating = False
lr = Cells(Rows.Count, "V").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "V") <> 0 Then
Rows(i + 1).Insert
Cells(i, "V").Select
Cells(i, "P").Copy Cells(i + 1, "P")
Cells(i, "R").Cut Cells(i + 1, "Q")
Cells(i, "V").Cut Cells(i + 1, "U")
End If
Next i

lr = Cells(Rows.Count, "W").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "W") <> 0 Then
Rows(i + 1).Resize(2).Insert
Cells(i, "P").Copy Cells(i + 1, "P").Resize(2)
Cells(i, "Q").Copy Cells(i + 1, "Q").Resize(2)
Cells(i, "R").Cut Cells(i + 2, "Q")
Cells(i + 1, "U") = Cells(i, "W") * -1
Cells(i + 2, "U") = Cells(i, "W")
Cells(i, "W").ClearContents
End If
Next i
Application.ScreenUpdating = True
End Sub
``````
0

Author Comment

ID: 41753531
not something like that exactly like that. Brilliant many thanks
0

LVL 31

Expert Comment

ID: 41753574
You're welcome. Thanks for the feedback.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
###### Suggested Courses
Course of the Month8 days, 14 hours left to enroll