tropics123
Board Regular
- Joined
- May 11, 2016
- Messages
- 85
Hi, I would greatly appreciate help on this as I'm stuck and macro doesn't work Here's what I'm trying to do:
1) Find all headers with the names "Int" and "Prin" and sum the two columns together and put the new result in column "Prin". It would override the previous numbers in "Prin"
2) Delete all numbers in the "Int" columns
3) In columns "Loan Dist" and "Prin", change the numbers to opposite signs (this has to be the last step so it doesn't effect the prin amount in step 1)
My macro is below. Thanks much!!
Example of original data
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]Loan Dist[/TD]
[TD]Int[/TD]
[TD]Prin[/TD]
[TD]Transfers[/TD]
[TD]Loan Dist[/TD]
[TD]Int[/TD]
[TD]Prin[/TD]
[TD]Gain/Loss[/TD]
[/TR]
[TR]
[TD]-450[/TD]
[TD]880[/TD]
[TD]20,000[/TD]
[TD][/TD]
[TD]-8,900[/TD]
[TD][/TD]
[TD]560,000[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]-250[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]-5[/TD]
[TD]65[/TD]
[TD]220,000[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]20[/TD]
[TD]1,500[/TD]
[TD][/TD]
[TD]-180[/TD]
[TD]86[/TD]
[TD]86,000[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]-100[/TD]
[TD]6000[/TD]
[TD]100,000[/TD]
[TD][/TD]
[TD]-120[/TD]
[TD]123[/TD]
[TD]150,000[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Desired outcome
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]Loan Dist[/TD]
[TD]Int[/TD]
[TD]Prin[/TD]
[TD]Transfers[/TD]
[TD]Loan Dist[/TD]
[TD]Int[/TD]
[TD]Prin[/TD]
[TD]Gain/Loss[/TD]
[/TR]
[TR]
[TD]450[/TD]
[TD][/TD]
[TD]-20,880[/TD]
[TD]
[/TD]
[TD]8,900[/TD]
[TD]
[/TD]
[TD]-560,000[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]250[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]5[/TD]
[TD][/TD]
[TD]-220,065[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]
[/TD]
[TD][/TD]
[TD]-1,520[/TD]
[TD]
[/TD]
[TD]180
[/TD]
[TD]
[/TD]
[TD]-86,086[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]100[/TD]
[TD]
[/TD]
[TD]-106,000[/TD]
[TD]
[/TD]
[TD]120[/TD]
[TD]
[/TD]
[TD]-150,123[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Macro:
Sheets("Sheet3").Select
Dim A As Range
Dim i As Long
Set A = Rows(1).Find(what:="Int", LookIn:=xlValues, lookat:=xlPart)
Set A = Rows(1).Find(what:="Prin", LookIn:=xlValues, lookat:=xlPart).FormulaR1C1 = "Sum(RC1, RC2)"
Do
Set A = Rows(1).Find(what:="Loan Dist", LookIn:=xlValues, lookat:=xlPart)
Set A = Rows(1).Find(what:="Prin", LookIn:=xlValues, lookat:=xlPart)
If A Is Nothing Then Exit Do
For i = LBound(A) To UBound(A)
A(i, 1) = -A(i, 1)
Next i
Loop
End Sub
1) Find all headers with the names "Int" and "Prin" and sum the two columns together and put the new result in column "Prin". It would override the previous numbers in "Prin"
2) Delete all numbers in the "Int" columns
3) In columns "Loan Dist" and "Prin", change the numbers to opposite signs (this has to be the last step so it doesn't effect the prin amount in step 1)
My macro is below. Thanks much!!
Example of original data
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]Loan Dist[/TD]
[TD]Int[/TD]
[TD]Prin[/TD]
[TD]Transfers[/TD]
[TD]Loan Dist[/TD]
[TD]Int[/TD]
[TD]Prin[/TD]
[TD]Gain/Loss[/TD]
[/TR]
[TR]
[TD]-450[/TD]
[TD]880[/TD]
[TD]20,000[/TD]
[TD][/TD]
[TD]-8,900[/TD]
[TD][/TD]
[TD]560,000[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]-250[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]-5[/TD]
[TD]65[/TD]
[TD]220,000[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]20[/TD]
[TD]1,500[/TD]
[TD][/TD]
[TD]-180[/TD]
[TD]86[/TD]
[TD]86,000[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]-100[/TD]
[TD]6000[/TD]
[TD]100,000[/TD]
[TD][/TD]
[TD]-120[/TD]
[TD]123[/TD]
[TD]150,000[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Desired outcome
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]Loan Dist[/TD]
[TD]Int[/TD]
[TD]Prin[/TD]
[TD]Transfers[/TD]
[TD]Loan Dist[/TD]
[TD]Int[/TD]
[TD]Prin[/TD]
[TD]Gain/Loss[/TD]
[/TR]
[TR]
[TD]450[/TD]
[TD][/TD]
[TD]-20,880[/TD]
[TD]
[/TD]
[TD]8,900[/TD]
[TD]
[/TD]
[TD]-560,000[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]250[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]5[/TD]
[TD][/TD]
[TD]-220,065[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]
[/TD]
[TD][/TD]
[TD]-1,520[/TD]
[TD]
[/TD]
[TD]180
[/TD]
[TD]
[/TD]
[TD]-86,086[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]100[/TD]
[TD]
[/TD]
[TD]-106,000[/TD]
[TD]
[/TD]
[TD]120[/TD]
[TD]
[/TD]
[TD]-150,123[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Macro:
Sheets("Sheet3").Select
Dim A As Range
Dim i As Long
Set A = Rows(1).Find(what:="Int", LookIn:=xlValues, lookat:=xlPart)
Set A = Rows(1).Find(what:="Prin", LookIn:=xlValues, lookat:=xlPart).FormulaR1C1 = "Sum(RC1, RC2)"
Do
Set A = Rows(1).Find(what:="Loan Dist", LookIn:=xlValues, lookat:=xlPart)
Set A = Rows(1).Find(what:="Prin", LookIn:=xlValues, lookat:=xlPart)
If A Is Nothing Then Exit Do
For i = LBound(A) To UBound(A)
A(i, 1) = -A(i, 1)
Next i
Loop
End Sub
Last edited: