Results 1 to 4 of 4

Modifying Existing Code to Check if the entry exists

Threaded View

  1. #1
    Registered User
    Join Date
    07-22-2010
    Location
    Ontario
    MS-Off Ver
    Excel 2003
    Posts
    71

    Modifying Existing Code to Check if the entry exists

    Hi There,

    I need your help,

    I have a code below that works well with a userform that adds my data from my userform to an excel worksheet. It works great and all, but id like to modify it to have it check and see if the file number (fn) exists before writting it back to the worksheet, if it exists, then msgbox "Error: Record Cannot be added - (Duplicate Entry)" and do nothing else, if the file number does not exist, proceed as normal and execute the rest of the code.

    With Me 
        Select Case .h9.Value 
        Case "ACTIVE" 
            Set ws = Worksheets("Active_Data") 
            iRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Offset(1, 0).Row 
             
            ws.Cells(iRow, 1) = .h1 
            ws.Cells(iRow, 2).Value = .h2 
             
            ws.Cells(iRow, 3).Value = fn 
            Me.h3.Text = fn 
             
            ws.Cells(iRow, 4).Value = .h4 
            ws.Cells(iRow, 5).Value = .h5 
            ws.Cells(iRow, 6).Value = .h6 
             
            If notify.Value = "True" Then 
                ws.Cells(iRow, 7).Value = "Yes" 
            Else 
                ws.Cells(iRow, 7).Value = "No" 
            End If 
             
            If remind.Value = "True" Then 
                ws.Cells(iRow, 8).Value = "Yes" 
            Else 
                ws.Cells(iRow, 8).Value = "No" 
            End If 
             
            ws.Cells(iRow, 9).Value = .h7 
            ws.Cells(iRow, 10).Value = .h8 
            ws.Cells(iRow, 11).Value = .h9 
            ws.Cells(iRow, 12).Value = .h10 
            ws.Cells(iRow, 13).Value = .h11 
            ws.Cells(iRow, 14).Value = .h12 
            ws.Cells(iRow, 15).Value = .h13 
             
            ws.Cells(iRow, 16).Value = Now 
            Me.h14.Value = Now 
             
            MsgBox "The record has been sucessfully added!" _ 
            , vbInformation + vbOKOnly, "Record added" 
             
        Case "INACTIVE" 
            Set ws = Worksheets("Inactive_Data") 
            iRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Offset(1, 0).Row 
            ws.Cells(iRow, 1) = .h1 
            ws.Cells(iRow, 2).Value = .h2 
             
            ws.Cells(iRow, 3).Value = fn 
            Me.h3.Text = fn 
             
            ws.Cells(iRow, 4).Value = .h4 
            ws.Cells(iRow, 5).Value = .h5 
            ws.Cells(iRow, 6).Value = .h6 
             
            If notify.Value = "True" Then 
                ws.Cells(iRow, 7).Value = "Yes" 
            Else 
                ws.Cells(iRow, 7).Value = "No" 
            End If 
             
            If remind.Value = "True" Then 
                ws.Cells(iRow, 8).Value = "Yes" 
            Else 
                ws.Cells(iRow, 8).Value = "No" 
            End If 
             
            ws.Cells(iRow, 9).Value = .h7 
            ws.Cells(iRow, 10).Value = .h8 
            ws.Cells(iRow, 11).Value = .h9 
            ws.Cells(iRow, 12).Value = .h10 
            ws.Cells(iRow, 13).Value = .h11 
            ws.Cells(iRow, 14).Value = .h12 
            ws.Cells(iRow, 15).Value = .h13 
             
            ws.Cells(iRow, 16).Value = Now 
            Me.h14.Value = Now 
             
            MsgBox "The record has been sucessfully added!" _ 
            , vbInformation + vbOKOnly, "Record added" 
             
        End Select 
    End With
    Any help with this is greatly appreciated.

    Much thanks for all your help in advance.

    Thanks,

    Jay
    Last edited by jason_kelly; 12-31-2010 at 10:39 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1