i have written below code to self populate the "Update existing risk" form based on the selected risk ID:
Private Sub RiskID_Change()
Dim Sh As Worksheet
Set Sh = ThisWorkbook.Sheets("Risk_Register")
Dim i As Long
If Me.RiskID.Value <> "" Then
i = Application.Match(VBA.CLng(Me.RiskID.Value), Sh.Range("H:H"), 0)
If Sh.Range("k" & i).Value = "Open" Then Me.OptionButton1.Value = True
If Sh.Range("k" & i).Value = "Closed" Then Me.OptionButton2.Value = True
If Sh.Range("k" & i).Value = "For escalation" Then Me.OptionButton3.Value = True
Me.RiskType_CB.Value = Sh.Range("m" & i).Value
Me.RiskName_TX.Value = Sh.Range("n" & i).Value
Me.RiskDescription_TX.Value = Sh.Range("o" & i).Value
Me.ImpactDescription_TX.Value = Sh.Range("p" & i).Value
Me.AreaOfImpact_CB.Value = Sh.Range("q" & i).Value
Me.RiskValue_TX.Value = Sh.Range("r" & i).Value
Me.RiskOWner_TX.Value = Sh.Range("t" & i).Value
Me.Impact_CB.Value = Sh.Range("u" & i).Value
Me.Probablility_CB.Value = Sh.Range("v" & i).Value
Me.MitigationAction_TX.Value = Sh.Range("x" & i).Value
Me.PostMitigationValue_TX.Value = Sh.Range("y" & i).Value
Me.ResolveDate_TX.Value = Sh.Range("aa" & i).Value
Me.LastReviewedDate_TX.Value = Sh.Range("z" & i).Value
End If
End Sub
Private Sub UpdateRisk_CB_Click()
Dim Sh As Worksheet
Set Sh = ThisWorkbook.Sheets("Risk_Register")
Dim n As Long
n = Application.Match(VBA.CLng(Me.RiskID.Value), Sh.Range("H:H"), 0)
Sh.Unprotect "kk"
If Me.LastReviewedDate_TX.Value = "" Then
MsgBox "Please enter Last Review Date as dd/mm/yy format", vbCritical
Exit Sub
End If
Sh.Range("m" & n).Value = Me.RiskType_CB
Sh.Range("n" & n).Value = Me.RiskName_TX
Sh.Range("o" & n).Value = Me.RiskDescription_TX
Sh.Range("p" & n).Value = Me.ImpactDescription_TX
Sh.Range("q" & n).Value = Me.AreaOfImpact_CB
Sh.Range("r" & n).Value = Me.RiskValue_TX
Sh.Range("t" & n).Value = Me.RiskOWner_TX
Sh.Range("u" & n).Value = Me.Impact_CB
Sh.Range("v" & n).Value = Me.Probablility_CB
Sh.Range("x" & n).Value = Me.MitigationAction_TX
Sh.Range("y" & n).Value = Me.PostMitigationValue_TX
Sh.Range("z" & n).Value = Me.LastReviewedDate_TX
Sh.Range("aa" & n).Value = Me.ResolveDate_TX
If Me.OptionButton1.Value = True Then
Sh.Range("k" & n).Value = "Open"
End If
If Me.OptionButton2.Value = True Then
Sh.Range("k" & n).Value = "Closed"
End If
If Me.OptionButton3.Value = True Then
Sh.Range("k" & n).Value = "For Escalation"
End If
MsgBox "Updated Successfully", vbInformation
All works perfectly fine other than, as said, returned Risk Value is returned to the excel as a text rather than a number