VBA: User selects cells and with macro applies compound interest

MyAdventureHat

New Member
Joined
Sep 17, 2014
Messages
4
Hello VBA users way better than me,

I have a workbook with multiple tabs and several lines of budget numbers on each tab.

Each tab is a different project and no two tabs are the same.

Project budgets are arranged by task and Fiscal Year. My goal is to enable the end user of this code to select a random series of budget lines and with the help of a macro apply compounding interest to the selection. In my example below the rate is 1%.

This is my current code:
---------------------------------------
' Keyboard Shortcut: Ctrl+a

Sub Escalate_data()

Dim C As Range

For Each C In Selection
C.Offset(0, 0) = C.Value * 1.01
Next

End Sub
---------------------------------------

In the above, the user can select a random series of data, hit ctrl+a, and have the numbers increase by 1%.

I need help with finding a way for the user to select numbers across multiple years, hit ctrl+a, and have the macro apply an increase of 1.01 to the selection's first column of numbers, (1.01)(1.01) to the second, (1.01)(1.01)(1.01) to the third, and keep increasing for each consecutive column until it hits the end (last column selected in the series).

So if the data looks like the table below, and I randomly select the bolded cells (C2:F3), and press ctrl+a...

ABCDEFGH
12014201520162017201820192020
2Task A100100100100100100100
3Task B100100100100100100100
4Task C100100100100100100100

<TBODY>
</TBODY>


The new series will appear as below:
1ABCDEFGH
12014201520162017201820192020
2Task A100101102.01103.03104.06100100
3Task B100101102.01103.03104.06100100
4Task C100100100100100100100

<TBODY>
</TBODY>

Thanks in advance for your help and best of luck!

V/R,

Scott
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi!

Try this code. You can assign your favorite shorcut:

Code:
Sub Esc_by_Columns()
    Dim Col As Range, C As Range
    Dim A&
    
    Application.ScreenUpdating = 0
    For Each Col In Selection.Columns
        A = A + 1
        For Each C In Range(Col.Address)
            C.Value = C * 1.01 ^ A
        Next
    Next
    Set Col = Nothing: Set C = Nothing
    Application.ScreenUpdating = 1
End Sub

Please coment!
I hope it helps! Blessings!
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,535
Members
449,037
Latest member
tmmotairi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top