checksum; generate for sheet; already done?

  • Thread starter Thread starter cate
  • Start date Start date
C

cate

This really doesn't belong in a ss, but here it is.

We have a workbook that acts as a database. Lots of different stuff
in it. Lots of stuff can change (or purpose or otherwise). I need to
generate and publish a checksum.

I know the area I will check and how I'll 'brand' the sheet with the
result. I'd like to know if anyone has done this before. What to
watch out for or any tips. I sure you understand the problem. We
have to know, we REALLY have to know, what we have. Maybe someone
already has a canned routine.

Thank you.

By-the-way - Does the Excel community have a modules drop? Where
people put modules that might help others?
 
I don't know if this cuts the mustard, but here is a little checksum
program that generates a "finger print". You name the sheet you want
to monitor and the rows and columns to check and you get a 4 digit hex
code to display on you main sheet. It seems to work ok but who
knows. It runs only when you open the wb. It could use an initial
check of the named cell and pop up a message if the previous valued
differed from that save.

========================================================
Dim barrel As Long ' this is in the general area so subs can read it


Private Sub Workbook_Open()
Dim mySheet As Worksheet
Dim colIndex As Integer
Dim rowIndex As Integer
Dim iTmp As Integer
Dim cellText As String
Dim rgHome As Range
Dim checksum As Long
Dim colEnd As Integer
Dim rowEnd As Integer
Dim ws As Worksheet
Dim hexString As String

Set mySheet = Application.ThisWorkbook.Worksheets("DataSheet")
Set rgHome = mySheet.Cells(1, 1)

colEnd = 11
rowEnd = 8
barrel = 1#
checksum = 1000000000#
For colIndex = 1 To colEnd Step 1
For rowIndex = 1 To rowEnd Step 1
cellText = rgHome.offset(rowIndex, colIndex).Text
checksum = hashit(cellText, checksum)
Next ' row
Next ' col

Set rgHome = ThisWorkbook.Worksheets("Main").Range
("a_cell_name_where_you_put_the_checksum")
rgHome.Value2 = justFour(checksum)

End Sub

Function hashit(in_string As String, in_hash As Long)
Dim LIndex As Long
Dim character_long As Long
Dim character_string As String
Dim multiplier As Long
For LIndex = 1 To Len(in_string) Step 1
barrel = barrel + 1
character_string = Mid(in_string, LIndex, 1)
If Len(in_string) <> 0 Then
character_long = CLng(Asc(character_string))
barrel = barrel + 1
character_long = character_long * (((barrel Mod 32)) + 1)
in_hash = in_hash Xor character_long
End If
Next 'character in string
hashit = in_hash
End Function

Function justFour(checksum As Long)
Dim hexS As String
Dim iTmp As Integer
hexS = Hex(checksum)
iTmp = Len(hexS) - 4
If iTmp < 4 Then
justFour = Mid(hexS, iTmp, 4)
Else
justFour = Mid(hexS, iTmp, 4)
End If
End Function
 
Back
Top