+ Reply to Thread
Results 1 to 24 of 24

VBA userform_ preventing duplicate from different columns

  1. #1
    Registered User
    Join Date
    01-05-2023
    Location
    uk
    MS-Off Ver
    11
    Posts
    24

    Question VBA userform_ preventing duplicate from different columns

    Hi,

    please HELP, so i have set up the userform which is for my transport records. basically i have 40 columns worth of data (40 textboxes on my userform), columns D to O are reference numbers. for example column A =customer name, column B = collection date, column C = collection time, column D=ref1,column E=ref2 until we get to column O which is ref12. the issue i have is i cant have the same reference number in any of these columns, i need a solution where all twelve textboxes are checked against all columns D to O. example below (this customer is only using one REF so columns E-O will be left blank, second example is a customer using 3 REF's but the REF code 123 has already been used, note that this REF might not be in the same column/textbox as before. this is why it is important that all columns are checked.

    example 1
    A-Customer name:toys 4 u
    A-Customer name:toys 4 u (textbox1)
    B-collection date:15/01/2023 (textbox2)
    C-collection time: 09:00 (textbox3)
    D-ref1:123 (textbox4)

    example 2
    A-Customer name:toys 4 u (textbox1)
    B-collection date:15/01/2023 (textbox2)
    C-collection time: 09:00 (textbox3)
    D-ref1:456 (textbox4)
    E-ref2:789 (Textbox5)
    F-ref3:123 (textbox6)

    as you can see in example 2, textbox6 =column F is now a duplicate because this was recorded in example 1 but in textbox4=column D.

    i would also like a msgbox if a duplicate is found " Reference already exists, please use sequence e.g 123-1

    pleaseeeeeeeeeeeeeeeeeeeeee help!!!!

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,303

    Re: VBA userform_ preventing duplicate from different columns

    see big yellow banner - upload your workbook - help us to help you - far easier then to give you an in context solution that is relevant to your case.
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

  3. #3
    Registered User
    Join Date
    01-05-2023
    Location
    uk
    MS-Off Ver
    11
    Posts
    24

    Re: VBA userform_ preventing duplicate from different columns

    the file has failed to upload. any advise?

    sorry new to this

  4. #4
    Registered User
    Join Date
    01-05-2023
    Location
    uk
    MS-Off Ver
    11
    Posts
    24

    Re: VBA userform_ preventing duplicate from different columns

    ive attached a screenshot of the userform, as you can see my ref are in a multi page.

    also you can see the spreadsheet which the data is transferred to. i have made an example and highlighted in yellow a duplicate which has been entered. but i dont want this to happen

    this is the code i have but will only look up textbox29 in column D,

    'this code was added when i click the command button on the userform to insert the data to check for the duplicate

    Private Sub MAKEBOOKING_Click()
    Dim a As Long, x As Long
    a = Application.WorksheetFunction.CountIf(Sheet1.Range("D:D"), Me.TextBox29.Text)
    x = Application.WorksheetFunction.CountA(Sheet1.Range("D:D"))
    If Me.TextBox29 <> "" And a = 0 Then
    Sheet1.Range("a" & x).Value = Me.TextBox29.Text
    Else

    End If
    End Sub



    'this code was added aswell (unsure what this does apart from gthe msgbox)

    Private Sub TextBox29_AfterUpdate()

    Dim a As Long
    a = Application.WorksheetFunction.CountIf(Sheet1.Range("D:D"), Me.TextBox29.Text)

    If a >= 1 Then
    TextBox29 = ""
    MsgBox "REF number already Exist,Please check or add as sequence e.g 12345-1"
    End If
    End Sub




    basically i have textbox29,textbox30 to textbox40 but i need each textbox checked against each other

    so textbox29 which is in columnD needs to be checked against column D,E,F,G,H,I,J,K,L,M,N,O and then textbox30 will do the same,and then textbox31 and so on..

    the below can be found on the userform image which is "REFERENCE" in a multi page.
    textbox29 this data goes to columnD
    textbox30 this data goes to columnE
    textbox31 this data goes to columnF
    textbox32 this data goes to columnG
    textbox33 this data goes to columnH
    textbox34 this data goes to columnI
    textbox35 this data goes to columnJ
    textbox36 this data goes to columnK
    textbox37 this data goes to columnL
    textbox38 this data goes to columnM
    textbox39 this data goes to columnN
    textbox40 this data goes to columnO

    hope this help, file seems to be to big to upload other wise i would send over.

    please help
    Attached Files Attached Files
    Last edited by PLwolves87; 01-06-2023 at 07:36 AM. Reason: add code

  5. #5
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,303

    Re: VBA userform_ preventing duplicate from different columns

    sorry reluctant to open zip files - upload your actual file with the code and userform in it - desensitise any confidential data - it impossible to analyse pictures - we need to run the code in-situ to diagnose errors.

  6. #6
    Registered User
    Join Date
    01-05-2023
    Location
    uk
    MS-Off Ver
    11
    Posts
    24

    Re: VBA userform_ preventing duplicate from different columns

    sorry to sound stupid, but how do i upload the whole file, when i did try it said file failed to upload

  7. #7
    Registered User
    Join Date
    01-05-2023
    Location
    uk
    MS-Off Ver
    11
    Posts
    24

    Re: VBA userform_ preventing duplicate from different columns

    Quote Originally Posted by torachan View Post
    sorry reluctant to open zip files - upload your actual file with the code and userform in it - desensitise any confidential data - it impossible to analyse pictures - we need to run the code in-situ to diagnose errors.
    this is the code i have but will only look up textbox29 in column D,

    'this code was added when i click the command button on the userform to insert the data to check for the duplicate

    Private Sub MAKEBOOKING_Click()
    Dim a As Long, x As Long
    a = Application.WorksheetFunction.CountIf(Sheet1.Range("D:D"), Me.TextBox29.Text)
    x = Application.WorksheetFunction.CountA(Sheet1.Range("D:D"))
    If Me.TextBox29 <> "" And a = 0 Then
    Sheet1.Range("a" & x).Value = Me.TextBox29.Text
    Else

    End If
    End Sub



    'this code was added aswell (unsure what this does apart from gthe msgbox)
    Private Sub TextBox29_AfterUpdate()

    Dim a As Long
    a = Application.WorksheetFunction.CountIf(Sheet1.Range("D:D"), Me.TextBox29.Text)

    If a >= 1 Then
    TextBox29 = ""
    MsgBox "REF number already Exist,Please check or add as sequence e.g 12345-1"
    End If
    End Sub




    basically i have textbox29,textbox30 to textbox40 but i need each textbox checked against each other

    so textbox29 which is in columnD needs to be checked against column D,E,F,G,H,I,J,K,L,M,N,O and then textbox30 will do the same,and then textbox31 and so on..

    the below can be found on the userform image which is "REFERENCE" in a multi page.
    textbox29 this data goes to columnD
    textbox30 this data goes to columnE
    textbox31 this data goes to columnF
    textbox32 this data goes to columnG
    textbox33 this data goes to columnH
    textbox34 this data goes to columnI
    textbox35 this data goes to columnJ
    textbox36 this data goes to columnK
    textbox37 this data goes to columnL
    textbox38 this data goes to columnM
    textbox39 this data goes to columnN
    textbox40 this data goes to columnO

  8. #8
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,303

    Re: VBA userform_ preventing duplicate from different columns

    where is the uploaded workbook - 'crystal ball gazing' (aka "guessing") is a waste of time - I prefer to give a solution with one post if possible rather than waste time, at my time of life every second is precious.

  9. #9
    Registered User
    Join Date
    01-05-2023
    Location
    uk
    MS-Off Ver
    11
    Posts
    24

    Re: VBA userform_ preventing duplicate from different columns

    Quote Originally Posted by torachan View Post
    where is the uploaded workbook - 'crystal ball gazing' (aka "guessing") is a waste of time - I prefer to give a solution with one post if possible rather than waste time, at my time of life every second is precious.
    it said the file was to big to send, i have made a copy with some data in, i hope this helps, if not is there a way that i can send you the full file

    believe me i dont want to waste your time or anyones time here, i appreciate the help and hope you guys can solve this for me



    test .xlsx

  10. #10
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,303

    Re: VBA userform_ preventing duplicate from different columns

    you have uploaded a .xlsx file (no code, no form) - the file with the form/code has to be saved as a .xlsm file.

  11. #11
    Registered User
    Join Date
    01-05-2023
    Location
    uk
    MS-Off Ver
    11
    Posts
    24

    Re: VBA userform_ preventing duplicate from different columns

    Quote Originally Posted by torachan View Post
    you have uploaded a .xlsx file (no code, no form) - the file with the form/code has to be saved as a .xlsm file.
    the file which has the userforms and tabs for the data to go to keeps failing, im guessing because of the size of the file.

    is there another way of me to send this file to you?

  12. #12
    Registered User
    Join Date
    01-05-2023
    Location
    uk
    MS-Off Ver
    11
    Posts
    24

    Re: VBA userform_ preventing duplicate from different columns

    Quote Originally Posted by PLwolves87 View Post
    the file which has the userforms and tabs for the data to go to keeps failing, im guessing because of the size of the file.

    is there another way of me to send this file to you?
    ive saved the file as the below
    Microsoft Excel Macro-Enabled Worksheet (.xlsm)
    3.36 MB (3,525,722 bytes)

  13. #13
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,192

    Re: VBA userform_ preventing duplicate from different columns

    Your file is to big...The idea is to upload a sample file...
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  14. #14
    Registered User
    Join Date
    01-05-2023
    Location
    uk
    MS-Off Ver
    11
    Posts
    24

    Re: VBA userform_ preventing duplicate from different columns

    so how do i do a sample? how can i make the file smaller?

    ive sent a copy of what the spreadsheet would look like with all its columns, the only thing i cant upload with it is the userform because im guessing the amount of code makes the file to large.

    cant i not just copy all of the code from my userform and then post that in a message?

  15. #15
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,192

    Re: VBA userform_ preventing duplicate from different columns

    It is not going to help...We need to see your file...Code is written based on file setup...
    See if you can zip the file and attach...I will open your zip file...
    Also...Please explain in step by step detail what it is you are trying to accomplish...We are not mind readers...
    Your code and images have no value if we do not understand what you are wanting to achieve...

  16. #16
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,303

    Re: VBA userform_ preventing duplicate from different columns

    I have never seen a UserForm that large - it is most likely the data contained in the sheet - in your copy file cut it down to a couple of dozen rows.

  17. #17
    Registered User
    Join Date
    01-05-2023
    Location
    uk
    MS-Off Ver
    11
    Posts
    24

    Re: VBA userform_ preventing duplicate from different columns

    Quote Originally Posted by torachan View Post
    I have never seen a UserForm that large - it is most likely the data contained in the sheet - in your copy file cut it down to a couple of dozen rows.
    im extremely confused nowm as my sheet has no data in it, all that is set up is the column headers.

    ive done a zip file and now the file is 3116kb

  18. #18
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,192

    Re: VBA userform_ preventing duplicate from different columns

    Press Ctrl & Z on the sheet and see where the cursor ends up

    Try this...Open your file and also a blank excel file...Then move Userform to blank file and save as some other name...Then check size of that file...
    Last edited by sintek; 01-06-2023 at 12:45 PM.

  19. #19
    Registered User
    Join Date
    01-05-2023
    Location
    uk
    MS-Off Ver
    11
    Posts
    24

    Re: VBA userform_ preventing duplicate from different columns

    Quote Originally Posted by sintek View Post
    It is not going to help...We need to see your file...Code is written based on file setup...
    See if you can zip the file and attach...I will open your zip file...
    Also...Please explain in step by step detail what it is you are trying to accomplish...We are not mind readers...
    Your code and images have no value if we do not understand what you are wanting to achieve...
    i know your not mind readers and if i could upload the file i would have lol

    this is what im trying to do
    extbox29 - textbox40 are recording reference numbers, but i cant have the same reference number appear in any of my columns once the data has been transferred. each textbox is on one multi page on my userform. so for example textbox29 has REF123 and this isnt already recorded this will enter, if i then add a new booking and textbox29 is REF456 and then textbox30 is REF123 this will flag as a duplicate as this was already recorded in a different column on the data enter sheet.

    multi page.
    textbox29 this data goes to columnD
    textbox30 this data goes to columnE
    textbox31 this data goes to columnF
    textbox32 this data goes to columnG
    textbox33 this data goes to columnH
    textbox34 this data goes to columnI
    textbox35 this data goes to columnJ
    textbox36 this data goes to columnK
    textbox37 this data goes to columnL
    textbox38 this data goes to columnM
    textbox39 this data goes to columnN
    textbox40 this data goes to columnO

    this is the code i have but will only look up textbox29 in column D,

    'this code was added when i click the command button on the userform to insert the data to check for the duplicate

    Private Sub MAKEBOOKING_Click()
    Dim a As Long, x As Long
    a = Application.WorksheetFunction.CountIf(Sheet1.Range("D:D"), Me.TextBox29.Text)
    x = Application.WorksheetFunction.CountA(Sheet1.Range("D:D"))
    If Me.TextBox29 <> "" And a = 0 Then
    Sheet1.Range("a" & x).Value = Me.TextBox29.Text
    Else

    End If
    End Sub



    'this code was added aswell (unsure what this does apart from gthe msgbox)
    Private Sub TextBox29_AfterUpdate()

    Dim a As Long
    a = Application.WorksheetFunction.CountIf(Sheet1.Range("D:D"), Me.TextBox29.Text)

    If a >= 1 Then
    TextBox29 = ""
    MsgBox "REF number already Exist,Please check or add as sequence e.g 12345-1"
    End If
    End Sub




    basically i have textbox29 to textbox40 but i need each textbox checked against each other

    so textbox29 which is in columnD needs to be checked against column D,E,F,G,H,I,J,K,L,M,N,O and then textbox30 will do the same,and then textbox31 and so on..

  20. #20
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,192

    Re: VBA userform_ preventing duplicate from different columns

    You have already posted all your code...It is not going to help...All you are doing is cluttering this thread with nonsense..
    We need the file...
    Do as I suggested in Post 18

  21. #21
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,000

    Re: VBA userform_ preventing duplicate from different columns

    It's normally not officially approved of... but try a 3rd party file hosting site??
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  22. #22
    Registered User
    Join Date
    01-05-2023
    Location
    uk
    MS-Off Ver
    11
    Posts
    24

    Re: VBA userform_ preventing duplicate from different columns

    Quote Originally Posted by sintek View Post
    Press Ctrl & Z on the sheet and see where the cursor ends up

    Try this...Open your file and also a blank excel file...Then move Userform to blank file and save as some other name...Then check size of that file...
    its gone to 2635kb

  23. #23
    Registered User
    Join Date
    01-05-2023
    Location
    uk
    MS-Off Ver
    11
    Posts
    24

    Re: VBA userform_ preventing duplicate from different columns

    Quote Originally Posted by sintek View Post
    You have already posted all your code...It is not going to help...All you are doing is cluttering this thread with nonsense..
    We need the file...
    Do as I suggested in Post 18

    can i send the file via email?

  24. #24
    Registered User
    Join Date
    01-05-2023
    Location
    uk
    MS-Off Ver
    11
    Posts
    24

    Re: VBA userform_ preventing duplicate from different columns

    Quote Originally Posted by sintek View Post
    Press Ctrl & Z on the sheet and see where the cursor ends up

    Try this...Open your file and also a blank excel file...Then move Userform to blank file and save as some other name...Then check size of that file...
    the userform on its own is 17kb?

    think i will need to remake the userform and then repost here as i have no idea why this is so big.

    id like to thank you for taking a look and trying to help me. hopefully my next post will be the attached file

+ 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. Replies: 6
    Last Post: 01-30-2018, 04:56 PM
  2. Preventing Duplicate's, Multiple columns & on Multiple Tabs - Validation
    By Victoriak in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-12-2014, 04:22 AM
  3. [SOLVED] Preventing duplicate random gen
    By joe1joe1joe2 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-03-2014, 04:25 PM
  4. [SOLVED] Preventing Duplicate Entries
    By flashdisk in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-13-2013, 08:37 PM
  5. Preventing duplicate entries
    By BBS in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-21-2009, 03:54 PM
  6. Preventing Duplicate entries
    By Dave32 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-14-2008, 09:51 AM
  7. Preventing Duplicate Cells
    By BenBlair in forum Excel General
    Replies: 3
    Last Post: 05-19-2005, 02:06 PM

Tags for this Thread

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