Formula with rolling columns

Dan4321

New Member
Joined
Feb 29, 2016
Messages
2
Hi Guys!
Hope to find you well!

I got a problem with a VBA code.

here the problem:
I get 2 sheets: sheet1 and sheet2.

Sheet2 changes every day, fulling in one more column each day that passes. for example Day one there will be 2 column filled with data, day 2, 3 columns and so on.

I was wondering how i can write a formula in VBA on sheet1 (let's say in B7) for calculating the variation in %(e.g. expressed (N7-M7)/M7 ) of the last two columns in sheet2.

Ideally this formula will calculate the following
The first time, the formula will calculate (N7-M7)/M7, being N7 and M7 the last 2 column "not empty" in sheet2. The second time the formula will calculate (O7-N7)/N7, being O7 and N7 the last columns "not empty" in sheet 2. And so on.

Help would be amazing !
thanks !
Dan
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi Guys!
Hope to find you well!

I got a problem with a VBA code.

here the problem:
I get 2 sheets: sheet1 and sheet2.

Sheet2 changes every day, fulling in one more column each day that passes. for example Day one there will be 2 column filled with data, day 2, 3 columns and so on.

I was wondering how i can write a formula in VBA on sheet1 (let's say in B7) for calculating the variation in %(e.g. expressed (N7-M7)/M7 ) of the last two columns in sheet2.

Ideally this formula will calculate the following
The first time, the formula will calculate (N7-M7)/M7, being N7 and M7 the last 2 column "not empty" in sheet2. The second time the formula will calculate (O7-N7)/N7, being O7 and N7 the last columns "not empty" in sheet 2. And so on.

Help would be amazing !
thanks !
Dan
Hi Dan, welcome to the boards.

If I am understanding you correctly, does this do as you describe?

Code:
Sub TEST()
LastCol = Sheets("Sheet2").Cells(7, Columns.Count).End(xlToLeft).Column
Sheets("Sheet1").Range("B7").Formula = "=(" & Sheets("Sheet2").Cells(7, LastCol - 1) & "-" & Sheets("Sheet2").Cells(7, LastCol) & ")/" & Sheets("Sheet2").Cells(7, LastCol)
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,551
Messages
6,125,478
Members
449,233
Latest member
Deardevil

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