+ Reply to Thread
Results 1 to 16 of 16

VBA code for message box if data already exist.

  1. #1
    Registered User
    Join Date
    02-09-2014
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    15

    VBA code for message box if data already exist.

    Hello Expert,

    Please help me create vba code that message box will popup when data already exist in another sheet.

    I have a command button in sheet 1 and when I click this the data will automatically copied/transfer to sheet 2 and when the data already exist a message popup will diplay with "Yes" or "No" button.

    E.g: What if you want to compare the data entered into column A on "sheet 1" against the data in column A on "sheet 2"?

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: VBA code for message box if data already exist.

    Not much info to go on but Find or Application.Match will probably do the trick.
    Best to post example file with code you created for commandbutton.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Registered User
    Join Date
    02-09-2014
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: VBA code for message box if data already exist.

    Hello, bakerman2,

    What I want to do is when I clicked the Update Data button in Data_Entry and the data already exist in ER100_Activation_Configuration sheet a message box should be displayed.
    I want to check if the unique data under column E Row 19 of Data_Entry sheet was already exist.

    See attach file.
    Attached Files Attached Files
    Last edited by Master_Viper; 07-26-2016 at 05:39 PM.

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: VBA code for message box if data already exist.

    Number in column D is the same but format on Data Entry is different. What about that?

  5. #5
    Registered User
    Join Date
    02-09-2014
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: VBA code for message box if data already exist.

    Hello Expert,

    The file attached has been updated same format with ER100_Configuration_Activation sheet. Like what I have said in the previous post. I want to check if the data from Data_Entry sheet under column D row 19 is already exist in the ER100_Activation_Configuration sheet under column D. If that the case a message box popup will appear/display.

    Thanks in advance for the help.
    Attached Files Attached Files
    Last edited by Master_Viper; 07-27-2016 at 09:30 AM.

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: VBA code for message box if data already exist.

    Try this.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-09-2014
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: VBA code for message box if data already exist.

    Hello bakerman2,

    I got an error below in yellow highlighted font. Run-time error '13': Type mismatch.

    Private Sub CommandButton1_Click()
    Dim sh1 As Worksheet, a As String, b As String, c As String
    Dim fRow As Long
    Ln = 7
    Set sh1 = Sheets("Data_Entry")
    fRow = Application.Match(sh1.Range("E19"), Sheets("ER100_Activation_Configuration").Columns(4), 0)
    If Not IsError(fRow) Then MsgBox "Number already present": Exit Sub
    x = Mid(sh1.Range("E431"), 5, Ln)
    With Range("E431")
    .Value = x
    .NumberFormat = WorksheetFunction.Rept("0", Ln)
    End With
    Set sh1 = Sheets("Data_Entry")
    If sh1.Range("S448") = "N" Or sh1.Range("S448") = "ONT" Or sh1.Range("S448") = "PON" Then
    b = "3Spring"
    Else: sh1.Range("S448") = "Nest3"
    b = "4Spring"
    End If
    If sh1.Range("E448") = "2858097400100" Then
    c = "PS100"
    Else: sh1.Range("E448") = "2858041501100"
    c = "PS60"
    End If
    a = Array(sh1.Range("E19").Value, sh1.Range("E9").Value, sh1.Range("E7").Value, Mid(sh1.Range("E7"), 10, 4), sh1.Range("M446").Value, sh1.Range("O9").Value, _
    sh1.Range("E434").Value, Mid(sh1.Range("E434"), 5, 7), sh1.Range("S444").Value, sh1.Range("E440").Value, Mid(sh1.Range("E440"), 5, 7), _
    sh1.Range("E448").Value, c, sh1.Range("S448").Value, b)
    With Sheets("ER100_Activation_Configuration").Cells(Rows.Count, 4).End(xlUp).Offset(1)
    .Resize(, 21).Value = a
    .Resize(, 21).NumberFormat = "0"
    .Offset(, -2).Value = .Row() - 2
    .Offset(, -1).Value = Format(Now(), "mm-dd-yy")
    End With
    End Sub

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: VBA code for message box if data already exist.

    Format Data_Entry E19 as Number like it is on ER100_Activation_Configuration Column D.

  9. #9
    Registered User
    Join Date
    02-09-2014
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: VBA code for message box if data already exist.

    Hello bakerman2,

    Follow your instruction above but still same error occured. ANy help on this.

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: VBA code for message box if data already exist.

    See example file.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    02-09-2014
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: VBA code for message box if data already exist.

    bakerman2 tried the sample above it's working when click the update button in the Data_Entry with the same number in the column E row 19, but when I change any number in the same column still run-time 13 mismatch appear.

  12. #12
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: VBA code for message box if data already exist.

    Try this.
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    02-09-2014
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: VBA code for message box if data already exist.

    bakerman2 still unluckily the message box did not popup when there was data from ER100_Activation_Configuration sheets.

  14. #14
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: VBA code for message box if data already exist.

    I'm sorry but I'm done here. For me it runs like clockwork.
    When number exists msgbox pops up, when new number all data gets copied to other sheet.
    There's nothing more I can do.

  15. #15
    Registered User
    Join Date
    02-09-2014
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: VBA code for message box if data already exist.

    Anyone can debug the code together with the sample file.

    Thanks..

  16. #16
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: VBA code for message box if data already exist.

    What 's there to debug, it runs just fine.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Check First IF Sheet Is Exist With The Name Of Cell K7 If exist Then run the code
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-18-2015, 10:08 AM
  2. [SOLVED] Code to paste form data to next available row if cb1 value doesn't exist in column a
    By mezza89 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-08-2014, 06:20 PM
  3. [SOLVED] if value exist in colum return message..
    By bimo in forum Excel General
    Replies: 8
    Last Post: 04-24-2014, 01:37 PM
  4. [SOLVED] Pop up message box if duplicate exist
    By HerryMarkowitz in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-23-2013, 10:59 AM
  5. Replies: 6
    Last Post: 04-09-2012, 02:26 PM
  6. Replies: 1
    Last Post: 01-29-2012, 01:19 PM
  7. Data may exist in the sheet(s) message
    By cedtech23 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-21-2006, 10:15 AM

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