Hello Abdul
I probably have not understood exactly what you want.
But you may be able to adapt the following macros to exactly what you want
The basic coding idea:
In the Function , in section '1a) we check if the student name is present in the Results worksheet. If it is not present, then we don't need to go any further, so we Exit Function
In Rem 2 we effectively are looping down the results data and when we get a match we add the obtained marks to a string variable.
If you run the Test Calling routines on your test data ( https://excelfox.com/forum/showthrea...5233#post15233 ) , then you will get this message:
https://imgur.com/22nSRTj http://i.imgur.com/22nSRTj.jpg
Alan
Code:Sub TestByNme() Call CheckIfDoneItBefore("Rizwana") End Sub Sub TestByNmefromRange() Call CheckIfDoneItBefore(Worksheets("test").Range("D2").Value2) End Sub Public Function CheckIfDoneItBefore(ByVal StdntNme As String) Rem 1 Worksheets info Dim wsTst As Worksheet: Set wsTst = Worksheets("Test") Dim RegNo As String, Cls As String Let RegNo = wsTst.Range("D3").Value2: Let Cls = wsTst.Range("D4").Value2 Dim WsRst As Worksheet: Set WsRst = Worksheets("Result") Dim Lr As Long: Let Lr = WsRst.Range("A" & WsRst.Rows.Count & "").End(xlUp).Row ' https://excelfox.com/forum/showthread.php/2364-Delete-rows-based-on-match-criteria-in-two-excel-files-or-single-Excel-File?p=11467&viewfull=1#post11467 '1a) Names Present ( If the name of the student is not present then we don't need to go further Dim arrNms() As Variant: Let arrNms() = WsRst.Range("B1:B" & Lr & "").Value2 If IsError(Application.Match(StdntNme, arrNms(), 0)) Then Exit Function ' If Application.Match does not find a match then it willl not error but it will return a VBA error string, which we can test for '1b) Reg. No. Class Ob Marks Dim arrRgNm() As Variant, arrCls() As Variant, arrMks() As Variant Let arrRgNm() = WsRst.Range("C1:C" & Lr & "").Value2: Let arrCls() = WsRst.Range("D1:D" & Lr & "").Value2: Let arrMks() = WsRst.Range("E1:E" & Lr & "").Value2 Rem 2 Make a string of all the marks so far Dim Cnt As Long, MsgCnt As String For Cnt = 3 To Lr If arrNms(Cnt, 1) = StdntNme And arrRgNm(Cnt, 1) = RegNo And arrCls(Cnt, 1) = Cls Then ' we have a match Let MsgCnt = MsgCnt & arrMks(Cnt, 1) & vbCr & vbLf Else End If Next Cnt Rem 3 output MsgBox prompt:="You are already submitted the test paper and you have secured" & vbCr & vbLf & MsgCnt End Function





Reply With Quote
Bookmarks