VBA Help - Extract Formulas and Cell Location from a Range

Johnny Thunder

Well-known Member
Joined
Apr 9, 2010
Messages
693
Office Version
  1. 2016
Platform
  1. MacOS
Hi group,

I am working on a spreadsheet that has a row of formulas that are from the range ("BB4:BX4") what I am trying to do is get a list of the cell location and the formula within that cell. Anyone have any code that can do that?

I would need the results on "Sheet1" in cell A2.

Example on Sheet1

A2BB4"=IF(BJ4=TRUE,MAX(BB$2:BB3)+1,"""")"
A3BC4"=IF($BC3="""","""",IF(BF3=BF2,BH2+1,1))"
A4BD4"=IF($BC3="""","""",IF(BG3=BG2,BI2+1,1))"

<tbody>
</tbody>


Hopefully that makes sense.

Thanks in advance!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Well, I threw together something that does that sort of thing, just not formatted quite how you'd like.

Maybe it will get you moving in the right direction?

(It copies the location and formula of the range D1:E4 into the Cells A1:B4)

Code:
Sub cellInfo()


    Dim formulaRng As Range
    Set formulaRng = Sheets("Sheet1").Range("D1:E4")
    
    Dim rowNum As Integer
    Dim colNum As Integer
        
    For rowNum = 1 To formulaRng.Rows.Count
       
        For colNum = 1 To formulaRng.Columns.Count
       
            Sheets("Sheet1").Cells(rowNum, colNum).Value = formulaRng(rowNum, colNum).Address & "-" & formulaRng(rowNum, colNum).Formula
   
        Next colNum
        
    Next rowNum


End Sub

If you wanted to "Output" the results to a column instead of matching the layout of the range, you could use this sorta thing:

Code:
[LEFT][COLOR=#222222][FONT=Verdana]
Sheets("Sheet1").Cells(i, 1).Value = formulaRng(rowNum, colNum).Address & "-" & formulaRng(rowNum, colNum).Formula
i = i + 1
[/FONT][/COLOR][/LEFT]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,748
Messages
6,126,654
Members
449,326
Latest member
asp123

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