I have some code that isn’t working right. On the Student report page, I’ve written a sub that should change all cells’ formulas to the row number I specified. It successfully changes the formulas in cells A3:A6, but doesn't for any other cells. It’s not throwing any errors, the error handler doesn't trap anything, and it's compiling without issue, so I think it’s an issue with the logic. The code is in a private sub for the worksheet that it applies to: 'Student Report'.
Private Sub Worksheet_Change(ByVal Target As Range)
'Changes the row value in the worksheets' formulas to match the row value shown in B2 of the record the listbox(A2)
On Error GoTo ErrHandler
Dim lRow As String
If Target.Address = Range("A2").Address Then 'If the value of A2 changed, then
lRow = Range("B2").Value 'store the value of lRow - the line row value of the name that was selected in A2
Worksheets("Student Report").Range("A3:Q104").Replace What:="$*", Replacement:=lRow, LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False 'Replace any part of a cell that contains a $ and any number with the value in lRow
End If
Exit Sub
ErrHandler:
MsgBox Err.Number & "; " & Err.Description
Err.Clear
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
'Changes the row value in the worksheets' formulas to match the row value shown in B2 of the record the listbox(A2)
On Error GoTo ErrHandler
Dim lRow As String
If Target.Address = Range("A2").Address Then 'If the value of A2 changed, then
lRow = Range("B2").Value 'store the value of lRow - the line row value of the name that was selected in A2
Worksheets("Student Report").Range("A3:Q104").Replace What:="$*", Replacement:=lRow, LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False 'Replace any part of a cell that contains a $ and any number with the value in lRow
End If
Exit Sub
ErrHandler:
MsgBox Err.Number & "; " & Err.Description
Err.Clear
End Sub