Results 1 to 7 of 7

Thread: Display a message if already saved data

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    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
    Attached Files Attached Files
    Last edited by DocAElstein; 01-24-2021 at 08:18 PM.

Similar Threads

  1. Replies: 5
    Last Post: 09-16-2016, 12:57 PM
  2. Replies: 0
    Last Post: 07-07-2013, 01:52 AM
  3. Replies: 2
    Last Post: 07-02-2013, 02:36 PM
  4. Display sheet names in a message box
    By pells in forum Excel Help
    Replies: 4
    Last Post: 02-13-2013, 07:33 PM
  5. Display numbers in Lakhs
    By Prabhu in forum Excel Help
    Replies: 1
    Last Post: 01-29-2012, 02:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •