How to Apply Formula to every cell in range and print result for each cell in cell zz new line

Tardisgx

Board Regular
Joined
May 10, 2018
Messages
81
Excluding blank cells


Code:
Function showformula(rng As Range)
If rng.HasArray = True Then
    showformula = "{" & rng.Formula & "}"
    Else
        showformula = "Sheets(""" & ActiveSheet.Name & """). Range(""" & rng.Address & """)" & ".FormulaR1C1 = " & """" & rng.FormulaR1C1 & """"
    End If
End Function

So I put this UDF together. It shows a cell as it would appear in VBA. R1C1 format



My goal is to be able to "translate" for lack of a better term; each cell in a sheet range into VBA.



This means I can instantly take an existing workbook and produce VBA to recreate it.



So 1)show a user select box for specifying a range. Then Click Proceed and 2) the above UDF reads for every cell in the specified range and 3) prints each cell's result on a new line in cell ZZ.



is easy enough to googlefu

but 2) & 3) I do not know how I would write it
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
You should be aware of the forum rules on cross-posting by now, so please comply with them by adding the relevant links here to your posts in other forums. Thanks.
 
Upvote 0
https://www.reddit.com/r/excel/comments/brndla/how_to_apply_formula_to_every_cell_in_range_and/

Solution literally just occured found here

Code:
Sub BuildList()
    Dim c As Range
    Dim rngInput As Range
    Dim rngOutput As Range
    Dim i As Long

    'Ask our user for stuff
    Set rngInput = Application.InputBox("What cells do you want to read?", "Input", , , , , , 8)
    Set rngOutput = Application.InputBox("Where do you want output to go?", "Output", , , , , , 8)

    Application.ScreenUpdating = False

    'Write the answers
    For Each c In rngInput.Cells
        rngOutput.Cells(1).Offset(i).Value = ShowFormula(c)
        i = i + 1
    Next c
    Application.ScreenUpdating = True
End Sub
Function ShowFormula(rng As Range)
    If rng.HasArray = True Then
        ShowFormula = "{" & rng.Formula & "}"
    Else
        ShowFormula = "Sheets(""" & ActiveSheet.Name & """). Range(""" & rng.Address & """)" & ".FormulaR1C1 = " & """" & rng.FormulaR1C1 & """"
    End If
End Function
 
Last edited:
Upvote 0
That's not the only place you posted it...
 
Upvote 0

Forum statistics

Threads
1,224,987
Messages
6,182,161
Members
453,093
Latest member
Soffy

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