Elliottj2121
Board Regular
- Joined
- Apr 15, 2021
- Messages
- 56
- Office Version
- 365
- 2019
- Platform
- Windows
Hello
I am looking for some help with a scripting dictionary issue. What is going on is in Column F are posted check amounts to a database and Column H are the actual check values. I am trying to automate finding errors in posting and/or errors in the check writing. The image is how I would like the end result to look. For example, the posted amount in cell(5, 6) is three dollars short to its corresponding check in cell(11, 8) the column offset value is "No Match". The same goes for the posted amount in cell(12, 6), this check was posted to the database but no check was collected. Column H are values that are manually entered, Column F is the last column in a data set copied over from another spreadsheet. Any help is greatly appreciated! Thank you!!!
I am looking for some help with a scripting dictionary issue. What is going on is in Column F are posted check amounts to a database and Column H are the actual check values. I am trying to automate finding errors in posting and/or errors in the check writing. The image is how I would like the end result to look. For example, the posted amount in cell(5, 6) is three dollars short to its corresponding check in cell(11, 8) the column offset value is "No Match". The same goes for the posted amount in cell(12, 6), this check was posted to the database but no check was collected. Column H are values that are manually entered, Column F is the last column in a data set copied over from another spreadsheet. Any help is greatly appreciated! Thank you!!!
VBA Code:
Sub VerifyChecks(wkb As Workbook)
Dim Ws As Worksheet
Dim CkValues As Scripting.Dictionary
Dim R As Long, i As Long
Dim vlr As Variant
vlr = LastRow(Ws)
Set Ws = wkb.Worksheets(1)
If vlr > 0 Then
Set CkValues = New Dictionary
For R = 2 To vlr
If Not CkValues.Exists(Ws.Cells(R, 8).Value) Then
CkValues.Add CStr(Ws.Cells(R, 8).Value), R
End If
Next R
End If
If vlr > 0 Then
For R = 2 To vlr
If CkValues.Exists(CStr(Ws.Cells(R, 6).Value)) Then
i = CkValues(CStr(Ws.Cells(R, 6).Value))
Ws.Range("H" & R).Copy Ws.Cells(i, 7)
Else
Ws.Cells(i, 7).Offset(0, 1).Value = ""
End If
Next R
End If
End Sub
Function LastRow(sh As Worksheet) As Variant
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function