Using VBA to search workbook and hard code cells containing specific formulas

Cole_T

New Member
Joined
Aug 18, 2017
Messages
1
Hi,

I've seen some similar posts, and attempted to tweak the VBA in order for it to work for mu purposes, but I am relatively new to this and I haven't come up with anything that works properly yet.

I am looking to search through my workbook (quite a few sheets) to select and hard code all cells containing a VLOOKUP. From what I've read it seems that if you actually have the macro search through every cell in each sheet this will be pretty slow. In a few forums I'v noticed people using additional code combined with the VBA function to search and hard code the values being searched for which allows the macro to move quicker. I was also wondering how I could design this so that it will hard code the cells even if the VLOOKUP is not the first excel function in the formula.

As I mentioned before, I am pretty new to using VBA. Any advice and additional resources you can recommend to solve this issue and others in the future is greatly appreciated. I would post what I have written already, but if I'm being honest I don't think it will be useful whatsoever.

Thanks,

Cole
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Have a play around with this

Code:
Sub lookUp()
    For Each cell In ActiveSheet.UsedRange.Cells
        If cell.Formula Like "*VLOOKUP*" Then
            cell.Formula = cell.Value
        End If
    Next cell
End Sub
 
Last edited:
Upvote 0
To loop thru your workbook you'd do something like

Code:
Sub lookUp()

For Each aSheet In ActiveWorkbook.Worksheets


    For Each cell In aSheet.UsedRange.Cells
        If cell.Formula Like "*VLOOKUP*" Then
            cell.Formula = cell.Value
        End If
    Next cell


Next aSheet


End Sub
 
Upvote 0
This should be noticeably faster (especially if you have lots of filled cells) than visiting every cell individually...
Code:
[table="width: 500"]
[tr]
	[td]Sub ConvertVLOOKUPtoValues()
  Dim WS As Worksheet, FirstAddress As String, C As Range
  For Each WS In Worksheets
    With WS.UsedRange
      Set C = .Find("VLOOKUP", , xlFormulas, xlPart, SearchFormat:=False)
      If Not C Is Nothing Then
        FirstAddress = C.Address
        Do
          C.Value = C.Value
          Set C = .FindNext(C)
          If C Is Nothing Then Exit Do
        Loop While C.Address <> FirstAddress
      End If
    End With
  Next
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

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