VBA Macro: How to reference LastColumn variable in a simple formula

mortgus

New Member
Joined
May 1, 2020
Messages
1
Office Version
  1. 2013
Platform
  1. Windows
GOAL: I have a report that will grow by one column of data each day. Each day, I need to add a formula into the first empty column that will find the difference between the value in the last column and another fixed column that will never change.

PROBLEM: I have successfully set my variable (LastColumn) and used it to select the first cell I want to add the formula into. But I do not know the proper syntax for using my LastColumn variable within my formula.

If I were to manually type the formula into cell R5, it would read:
ActiveCell.Formula = "=Q5-M5"

I need to know how to substitute the Q for LastColumn.

Then for example, the next day I'd have another date of data and would need to enter into cell S5:
ActiveCell.Formula = "=R5-M5" (with R being substituted for LastColumn)

Sorry if this is basic -- I'm very new to VBA and I've spent hours trying to figure this out.
 

Attachments

  • screenshot.JPG
    screenshot.JPG
    18 KB · Views: 10

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,224,875
Messages
6,181,515
Members
453,050
Latest member
Obil

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