Obfuscate values in a spreadsheet

monikersupreme

New Member
Joined
Feb 15, 2016
Messages
6
I have a set of Excel spreadsheets that I am using as source data for a program I am writing. I want to create a set of data that retains the structure of the source data but obfuscates the cell values. In short, I need to keep the column names but should randomize numerical values, name strings, and dates.

Does anyone know of a VBA script that might do some or all of this already?

I was set to starting trying to write this from scratch but I feel (hope) perhaps some of the work may already be done...

Any advice would be much appreciated.

Thanks!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
For anyone scouting this forum in the future, I did manage to find a plugin (prior to coming here) called AnonymousXL but I think it's for purchase only. There is a paper, however, that details the algorithm along with certain case considerations:

http://ceur-ws.org/Vol-1209/paper_15.pdf
You may be able to make use of the Obfuscate macro below (if you are not in a hurry that is :lol: as I expect this code to be sloooow if you have lots of sheets and data). The following code replaces every letter (preserving existing letter casing though) in every cell containing a text constant with a random letter. Numerical values (includes dates) are retained as is so that any formulas, math or date calculations remain unaffected. In effect, you will have the identical workbook with all cells containing text constants as gibberish.
Code:
[table="width: 500"]
[tr]
	[td]Sub Obfuscate()
  Dim X As Long, WS As Worksheet, Cell As Range
  Dim Txt As String, UpperLetters As String, LowerLetters As String
  Randomize
  UpperLetters = Join(RandomizeArray(Split(StrConv("ABCDEFGHIJKLMNOPQRSTUVWXYZ", vbUnicode), Chr(0))), "")
  LowerLetters = Join(RandomizeArray(Split(StrConv("abcdefghijklmnopqrstuvwxyz", vbUnicode), Chr(0))), "")
  Application.ScreenUpdating = False
  For Each WS In ThisWorkbook
    For Each Cell In Cells.SpecialCells(xlConstants, xlTextValues)
      Txt = Cell.Value
      For X = 1 To Len(Txt)
        If Mid(Txt, X, 1) Like "[A-Z]" Then
          Mid(Txt, X) = Mid(UpperLetters, Asc(Mid(Txt, X, 1)) - 64, 1)
        ElseIf Mid(Txt, X, 1) Like "[a-z]" Then
          Mid(Txt, X) = Mid(LowerLetters, Asc(Mid(Txt, X, 1)) - 95, 1)
        End If
      Next
      Cell.Value = Txt
    Next
  Next
  Application.ScreenUpdating = True
End Sub

Function RandomizeArray(ArrayIn As Variant) As String()
  Dim Cnt As Long, RandomIndex As Long, Tmp As String
  Randomize
  For Cnt = UBound(ArrayIn) To LBound(ArrayIn) Step -1
    RandomIndex = Int((Cnt - LBound(ArrayIn) + 1) * Rnd + LBound(ArrayIn))
    Tmp = ArrayIn(RandomIndex)
    ArrayIn(RandomIndex) = ArrayIn(Cnt)
    ArrayIn(Cnt) = Tmp
  Next
  RandomizeArray = ArrayIn
End Function[/td]
[/tr]
[/table]
 
Upvote 0
For small workbooks with some VBA code, if we apply both types of obfuscation then almost nobody will invest time trying to understand or hack the file to "steal" the proprietary ideas on it. It is a workaround for the known security flaws in the Excel passwords. Thanks for sharing!
 
Last edited:
Upvote 0
In this approach:
- the columnheaders will not be affected
- identical string will get identical obfuscation strings

Code:
Sub M_snb()
   Randomize
   
   With CreateObject("scripting.dictionary")
      For Each it In Sheets(1).UsedRange.Offset(1).SpecialCells(2, 2)
         .Item(it) = Join(Array(Chr(65 + Int(26 * Rnd)), Chr(65 + Int(26 * Rnd)), Chr(65 + Int(26 * Rnd)), Chr(65 + Int(26 * Rnd)), Chr(65 + Int(26 * Rnd)), Chr(65 + Int(26 * Rnd)), Chr(65 + Int(26 * Rnd)), Chr(65 + Int(26 * Rnd)), Chr(65 + Int(26 * Rnd)), Chr(65 + Int(26 * Rnd)), Chr(65 + Int(26 * Rnd)), Chr(65 + Int(26 * Rnd)), Chr(65 + Int(26 * Rnd))), "")
      Next
      
      For Each it In .keys
          Sheets(1).UsedRange.Offset(1).Replace it, .Item(it), 1
      Next
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,115
Messages
6,176,479
Members
452,729
Latest member
fizzay_pop

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