I'm hoping someone can help me find out what I'm missing in this code...I'm a novice w/ VBA in Excel. What I'm trying to accomplish is: compare the value from one worksheet ("UserProf") column to a value in another worksheet ("DeptClasses") column. If those values are the same, update a separate cell in the first worksheet with a value from another column from the second worksheet. This will also need to loop through the values in the first worksheet looking for a match.
In essence, if the value in A1 in sheet 1 equals the value in sheet 2's cell D1, or D2, or D3, etc., set the value in cell A2 on sheet 1 to the value in sheet 2's matching row next column (i.e. if D1 in sheet 2 matches sheet 1 A1, set A2 to the value currently in sheet 2's E2 cell, etc.).
Each sheet's column has unique values (no duplicates), and is a number but stored as a text value. I've tried changing the format of the cells to Number, with no change in the results. The range of columns in each sheet is fixed (hence setting the "To lastXxx" as a fixed integer and not using End(xlUp).Row to set the value. What's really irritating to me is that I've used this approach for other spreadsheets/cross-sheet comparison and it works as I would expect.
When I was trying to troubleshoot this, I did add more variables to display in the Locals window in VBA and 'stepped into' the script - that is, see the values that were actually being evaluated, etc.; from what I can tell the "If" statement never evaluates to "True" even when I can see in the Locals that the cell values being compared do match.
I know there may be a more efficient(?) way to set up the range, etc., but this was a way that worked for me in the past, so was trying to keep in that format - mostly b/c I understand it :-)
Am I missing something? Where did I goof? Appreciate any help/feedback!!
Sub Profiles()
Dim lastDepClass As Integer
Dim lastClass As Integer
Dim DepClass As Integer
Dim Class As Integer
lastDepClass = 137
lastClass = 106
For Class = 3 To lastClass
For DepClass = 2 To lastDepClass
If Sheets("UserProf").Cells(Class, 1).Value = Sheets("DeptClasses").Cells(DepClass, 5).Value Then
Sheets("DeptClasses").Cells(DepClass, 6) = Sheets("UserProf").Cells(DepClass, 5).Value
End If
Next DepClass
Next Class
End Sub