Record formulas in VBA from spreadsheet cell

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,368
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a spreadsheet with multiple columns. I would like to record all of the formulas into VBA for the sole purposes of restoring those formulas if lost or damaged somehow.

I know I can manually take the steps in VBA by turning on the macro recorder, entering the cells and selecting F2, hit tab and that formula will be written into VBA in the R1C1 format as seen below. Is there a way to automate this to where I can find the last column of row 1 and have this process look thru row 2 starting at A2 and finding a cell with a formula and recording it to VBA?

VBA Code:
Sub Macro2()
    ActiveCell.Formula2R1C1 = _
        "=FILTER(Attendance!R4C1:INDEX(Attendance!C1,LastRow),Attendance!R4C2:INDEX(Attendance!C2,LastRow)=1)"
    Range("B2").Select
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Writing code is like writing a letter or similar document in that you do it manually. When you need it, you can use it. You're asking for a way for an application/code to write the letter for you, or put another way, for code to write code. This is possible but very complicated and frankly, not worth the effort. Maybe there is someone around here who is quite experienced with coding at this level but I think it's rare. Far easier for you to keep file backups or store your formulas in a hidden sheet.
 
Upvote 1
Hi Micron and thank you for your time. I did find a solution on Contextures that will meet my needs.
 
Upvote 0
It's customary to post a link to your solution in case anyone reading this in the future could use the info. In that case, you could also mark that post as the solution if you wish.
 
Upvote 0
I misunderstood your issue. I thought you wanted code to write code for you. Sorry.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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