+ Reply to Thread
Results 1 to 2 of 2

Userform for data entry checking is a value exists

  1. #1
    Registered User
    Join Date
    09-15-2013
    Location
    Jandakot, Western Australia
    MS-Off Ver
    Excel 2010
    Posts
    1

    Userform for data entry checking is a value exists

    Folks.
    A novice to VBA, I have created a user form that data enters individually numbered Quality cards (QC) into a spreadsheet.
    I am trying to find out how I write the code to check to see if the QC has previously been entered before it executes the populate code?

    The number is additionally annoying as when my code does populate the spreadsheet it populates the number as text. I physically need to go into my spreadsheet and convert all enrtered cards to number format. Does anyone have a solution to that? Voucher.Value refers to the QC number textbox.



    Current code

    Private Sub actionstaken_Change()

    End Sub

    Private Sub Allocated_Change()

    End Sub




    Private Sub btnAddMETL_Click()
    Dim iRow As Long
    Dim ws As Worksheet



    Voucher.Value = CDec(Voucher.Value)


    '''''''''''''''''''''''''''''''''''''''''''''''''
    ' Get the values from the form and stick the values
    ' into a few global variables
    '''''''''''''''''''''''''''''''''''''''''''''''''

    gsCallSign = Callsign.Value
    gsVoucher = Voucher.Value
    gsObserver = OT.Value
    gdDateTime = DateTime.Value
    gsObservations = Observations.Value
    gsRecommendation1 = Recommendation1.Value
    gsScenarioNo = ScenarioNo.Value
    gsAllocated = Allocated.Value
    gsCourse = Course.Value
    gsActionstaken = Actionstaken.Value
    gsDateclosed = Dateclosed.Value
    gsClosedby = Closedby.Value
    gsAdvised = Advised.Value



    ''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Pick the data storage Worksheet
    ''''''''''''''''''''''''''''''''''''''''''''''''''
    Set ws = Worksheets("Quality Cards")
    Sheets("Quality Cards").Select
    'find first empty row in database
    iRow = ws.Cells(Rows.Count, 1) _
    .End(xlUp).Offset(1, 0).Row



    ''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Transfer the data from the form to the data sheet
    ''''''''''''''''''''''''''''''''''''''''''''''''''
    Cells(iRow, 1).Value = gsVoucher
    Cells(iRow, 2).Value = gdDateTime
    Cells(iRow, 3).Value = gsObserver
    Cells(iRow, 4).Value = gsScenarioNo
    Cells(iRow, 5).Value = gsCallSign
    Cells(iRow, 6).Value = gsCourse
    Cells(iRow, 7).Value = gsObservations
    Cells(iRow, 8).Value = gsRecommendation1
    Cells(iRow, 9).Value = gsAllocated
    Cells(iRow, 10).Value = gsActionstaken
    Cells(iRow, 11).Value = gsDateclosed
    Cells(iRow, 12).Value = gsClosedby
    Cells(iRow, 13).Value = gsAdvised
    Sheets("Entry Form").Select

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Once the data has been written to the data sheet
    ' reset the form by removing the fields most likely to change
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Callsign.Value = ""
    Voucher.Value = ""
    OT.Value = gsObserver
    DateTime.Value = gdDateTime
    Observations.Value = ""
    Recommendation1.Value = ""
    ScenarioNo.Value = gsScenarioNo
    Allocated.Value = ""
    Course.Value = ""
    Actionstaken.Value = ""
    Dateclosed.Value = ""
    Closedby.Value = ""
    Advised.Value = ""



    Voucher.SetFocus

    ' Now we go back to the form for entry of the next Observation.

    End Sub

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Userform for data entry checking is a value exists

    Hi, mdrover,

    please wrap you procedure with code-tags for better readability.

    The outcome of a textbox is a string, you would need to change that using a conversion like CLng(Voucher.Value) or maybe CInt, CDbl.

    No need to place the contents in variables and write from there, cells could be filled directly from the textboxes. And if you use a With-Statement you would not need to activate the target sheet, please mind that the cells you write to must be addressed to that worksheet as well by putting a dot in front.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

+ 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. Checking if a file exists?
    By TomWolowiec in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 07-31-2013, 03:58 PM
  2. Check if an entry exists in a column before entering data
    By jpruffle in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-29-2009, 06:39 PM
  3. Checking if a data point exists on a chart
    By CFD in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-12-2008, 09:08 AM
  4. Checking & Forcing Data Entry in Cells
    By robertguy in forum Excel General
    Replies: 1
    Last Post: 01-23-2006, 02:10 PM
  5. [SOLVED] checking if an url exists
    By Aldo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-09-2005, 06:05 PM

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