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

[TABLE="width: 250"]
<tbody>[TR]
[TD]A2[/TD]
[TD]BB4[/TD]
[TD]"=IF(BJ4=TRUE,MAX(BB$2:BB3)+1,"""")"[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]A3[/TD]
[TD]BC4[/TD]
[TD]"=IF($BC3="""","""",IF(BF3=BF2,BH2+1,1))"[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]A4[/TD]
[TD]BD4[/TD]
[TD]"=IF($BC3="""","""",IF(BG3=BG2,BI2+1,1))"[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


Hopefully that makes sense.

Thanks in advance!
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,223,886
Messages
6,175,190
Members
452,616
Latest member
intern444

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