VBA to replace HsGetValue with value

Thomazz

New Member
Joined
Dec 28, 2017
Messages
24
Hello all,

I'm on the look-out for something which I think will be relatively easy. I'm looking for a macro/VBA-code that

  • will cycle through every sheet of a workbook
  • which simply replaces cells that have a formula that includes a HsGetValue with their value (basically as if you would be copy/paste values the cell).

I have Excels built based on SmartView with HsGetValue formulas. However, when I mail this to people that don't have the SmartView set-up, the cells with HsGetValue default to N/A. I want to transform those to their values. However, I want to keep normal formulas (like totals, index/match, ...) that don't have HsGetValue so the user can see how the document is built up.

Whoever that can help me, would save me a bunch of work.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
How about
VBA Code:
Sub Thomazz()
   Dim Ws As Worksheet
   Dim Rng As Range, Cl As Range
   
   For Each Ws In Worksheets
      On Error Resume Next
      Set Rng = Ws.UsedRange.SpecialCells(xlFormulas)
      On Error GoTo 0
      If Not Rng Is Nothing Then
         For Each Cl In Rng
            If InStr(1, Cl.Formula, "hsgetvalue", vbTextCompare) > 0 Then Cl.Value = Cl.Value
         Next Cl
      End If
   Next Ws
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Sub Thomazz()
   Dim Ws As Worksheet
   Dim Rng As Range, Cl As Range
  
   For Each Ws In Worksheets
      On Error Resume Next
      Set Rng = Ws.UsedRange.SpecialCells(xlFormulas)
      On Error GoTo 0
      If Not Rng Is Nothing Then
         For Each Cl In Rng
            If InStr(1, Cl.Formula, "hsgetvalue", vbTextCompare) > 0 Then Cl.Value = Cl.Value
         Next Cl
      End If
   Next Ws
End Sub

Just tested it, and seems to work absolutely great !

Small additional question : how would this code look if I only want this on a range I selected myself as opposed to the full workbook ?
 
Upvote 0
How about
VBA Code:
Sub Thomazz()
   Dim Rng As Range, Cl As Range
   
   On Error Resume Next
   Set Rng = Selection.SpecialCells(xlFormulas)
   On Error GoTo 0
   If Not Rng Is Nothing Then
      For Each Cl In Rng
         If InStr(1, Cl.Formula, "hsgetvalue", vbTextCompare) > 0 Then Cl.Value = Cl.Value
      Next Cl
   End If
End Sub
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,199
Members
449,072
Latest member
DW Draft

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