Solved

VBA to find and move

Posted on 2016-08-12
3
45 Views
Last Modified: 2016-08-12
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
Comment
Question by:Jagwarman
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
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
MsgBox "Task Completed.", vbInformation
End Sub

Open in new window

0
 

Author Comment

by:Jagwarman
ID: 41753531
not something like that exactly like that. Brilliant many thanks
0
 
LVL 28

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41753574
You're welcome. Thanks for the feedback.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now