Document formulas on sheet 2

boninm

New Member
Joined
Jan 31, 2025
Messages
16
Office Version
  1. 365
Platform
  1. Windows
Hi everyone

I want to do a VBA script that will document on sheet2, all of the formulas from sheet1.

I got the loop going (a simple loop for now 5x5). Since I'm able to write to the cell, I'll be able to read it.
But I'm having an issue getting the cell reference from sheet1 to a cell on sheet2
As for the formula, I will use the FORMULATEXT function

That's where I'm stuck.

Thanks in advance.

------------
VBA Code:

VBA Code:
Sub CycleThrough()
Dim VRows As Integer
Dim VColumns As Integer

For VColumns = 1 To 5
    For VRows = 1 To 5
        'Worksheets("Sheet1").Cells(Counter, 3).Value = CELL("address",Counter&3)
        VColumns2 = CStr(VColumns)
        VRows2 = CStr(VRows)
        Worksheets("Sheet1").Cells(VColumns, VRows).Value = VColumns2 & "," & VRows2 '(Columns 1st, then Rows)
    Next VRows
Next VColumns
End Sub

-------------------------

Document formulas on sheet2.xlsm
ABCDE
11,11,21,31,41,5
22,12,22,32,42,5
33,13,23,33,43,5
44,14,24,34,44,5
55,15,25,35,45,5
6
7
8ExampleAB
91AFGSGF=Z1+Z2
102=MATCH(…..=ETC…
113=xlookup(…...AKJDFH
124ADGFSFGA;KDLJF=
135SFGSGF=ETC…
14
15Output on Sheet 2If cell starts with "=", then Column A will have the Cell Reference, and Column B have the formulatext info
16
17A2=MATCH(…..
18A3=xlookup(…...
19B1=Z1+Z2
20B2=ETC…
21B5=ETC…
Sheet1
Cell Formulas
RangeFormula
D17:D18D17=C10
D19:D20D19=D9
D21D21=D13
 

Attachments

  • Document formulas on sheet2.jpg
    Document formulas on sheet2.jpg
    63.2 KB · Views: 2
Last edited by a moderator:
Just to confirm, is this what you are looking for in sheet2?
Book1
ABCD
8ExampleAB
91Text1=SUMPRODUCT
102=Sum=Vlookup
113=XlookupText4
124Text2Text5
135=Text3=EDate
Sheet1
Cell Formulas
RangeFormula
D10D10=Vlookup
C13C13=Text3
D13D13=EDate

Book1
AB
1Cell ReferenceExtracted Formula
2D9=SUMPRODUCT
3C10=Sum
4D10=Vlookup
5C11=Xlookup
6C13=Text3
7D13=EDate
Sheet2
 
Upvote 0
When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug & copy. My signature block at the bottom of this post has more details. I have added the tags for you this time. 😊

Give this a try with a copy of your workbook.

VBA Code:
Sub List_Formulas()
  Dim c As Range
  Dim i As Long
  
  i = 1
  With Sheets("Sheet2")
    .UsedRange.Clear
    .Columns("A:B").NumberFormat = "@"
    .Range("A1:B1").Value = Array("Cell", "Formula")
    For Each c In Sheets("Sheet1").UsedRange.SpecialCells(xlFormulas)
      i = i + 1
      .Range("A" & i).Resize(, 2).Value = Array(c.Address(0, 0), c.Formula)
    Next c
    .UsedRange.Columns.AutoFit
  End With
End Sub
 
Upvote 0
Solution
Just to confirm, is this what you are looking for in sheet2?
Book1
ABCD
8ExampleAB
91Text1=SUMPRODUCT
102=Sum=Vlookup
113=XlookupText4
124Text2Text5
135=Text3=EDate
Sheet1
Cell Formulas
RangeFormula
D10D10=Vlookup
C13C13=Text3
D13D13=EDate

Book1
AB
1Cell ReferenceExtracted Formula
2D9=SUMPRODUCT
3C10=Sum
4D10=Vlookup
5C11=Xlookup
6C13=Text3
7D13=EDate
Sheet2
yes
 
Upvote 0
When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug & copy. My signature block at the bottom of this post has more details. I have added the tags for you this time. 😊

Give this a try with a copy of your workbook.

VBA Code:
Sub List_Formulas()
  Dim c As Range
  Dim i As Long
 
  i = 1
  With Sheets("Sheet2")
    .UsedRange.Clear
    .Columns("A:B").NumberFormat = "@"
    .Range("A1:B1").Value = Array("Cell", "Formula")
    For Each c In Sheets("Sheet1").UsedRange.SpecialCells(xlFormulas)
      i = i + 1
      .Range("A" & i).Resize(, 2).Value = Array(c.Address(0, 0), c.Formula)
    Next c
    .UsedRange.Columns.AutoFit
  End With
End Sub
I will try your code.

Thank you for the explanation about the code tags. new at this.
I will read your info.
Thanks again
 
Upvote 0

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