+ Reply to Thread
Results 1 to 20 of 20

User form not adding data to sheet

Hybrid View

Ashleytaylor1702 User form not adding data to... 12-09-2020, 05:45 AM
vba_php Re: User form not adding data... 12-09-2020, 05:51 AM
Ashleytaylor1702 Re: User form not adding data... 12-09-2020, 06:01 AM
bakerman2 Re: User form not adding data... 12-09-2020, 05:55 AM
Ashleytaylor1702 Re: User form not adding data... 12-09-2020, 06:05 AM
romperstomper Re: User form not adding data... 12-09-2020, 06:11 AM
Ashleytaylor1702 Re: User form not adding data... 12-09-2020, 06:16 AM
vba_php Re: User form not adding data... 12-09-2020, 06:51 AM
Ashleytaylor1702 Re: User form not adding data... 12-09-2020, 07:13 AM
romperstomper Re: User form not adding data... 12-09-2020, 07:15 AM
Ashleytaylor1702 Re: User form not adding data... 12-09-2020, 07:17 AM
romperstomper Re: User form not adding data... 12-09-2020, 07:28 AM
Ashleytaylor1702 Re: User form not adding data... 12-09-2020, 08:59 AM
romperstomper Re: User form not adding data... 12-09-2020, 10:03 AM
Ashleytaylor1702 Re: User form not adding data... 12-09-2020, 10:26 AM
Ashleytaylor1702 Re: User form not adding data... 12-10-2020, 05:33 AM
bakerman2 Re: User form not adding data... 12-09-2020, 11:17 AM
torachan Re: User form not adding data... 12-09-2020, 11:42 AM
BrunoCampanini Re: User form not adding data... 12-09-2020, 12:35 PM
bakerman2 Re: User form not adding data... 12-10-2020, 06:15 AM
  1. #1
    Registered User
    Join Date
    07-10-2018
    Location
    Uk
    MS-Off Ver
    MS365 Version 2102
    Posts
    86

    User form not adding data to sheet

    Hi,

    Can any one have a look at the following and see if I am missing anything obvious

    When i run the user form I get no errors but no text is entered to relevant cells

    Private Sub cmdAddTooling_Click()
    Dim wks As Worksheet
    Dim AddNew As Range
    Set wks = Sheet1
    Set AddNew = wks.Range("A65356").End(xlUp).Offset(1, 0)
    
    AddNew.Offset(0, 0).Value = txtPartNumber.Text
    AddNew.Offset(0, 1).Value = txtTool.Text
    AddNew.Offset(0, 2).Value = txtDrawing.Text
    AddNew.Offset(0, 3).Value = txtNumber.Text
    End Sub
    Also could the same
    AddNew.Offset(0, 0).Value = txtPartNumber.Text
    be used for a combo box?

    Many Thanks

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: User form not adding data to sheet

    have you tried adding to the uf qualifier?
    AddNew.Offset(0, 0).Value = USERFORM_name.txtPartNumber
    the code works fine for me:
    Attached Images Attached Images

  3. #3
    Registered User
    Join Date
    07-10-2018
    Location
    Uk
    MS-Off Ver
    MS365 Version 2102
    Posts
    86

    Re: User form not adding data to sheet

    Just tried that and still no joy

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,356

    Re: User form not adding data to sheet

    Are you sure your column A is empty below the last entered data?

    Because otherwise you are entering data somewhere down your worksheet.

    Also Range("A65536") is oldskool, use Range("A" & wks.Rows.Count) instead.
    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.

  5. #5
    Registered User
    Join Date
    07-10-2018
    Location
    Uk
    MS-Off Ver
    MS365 Version 2102
    Posts
    86

    Re: User form not adding data to sheet

    I have just checked and Column A is empty and I have amended the code but still not working

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: User form not adding data to sheet

    If you're not getting an error, then the data is going somewhere. Are you sure you're looking at the correct sheet? Sheet1 is a codename and is not necessarily the sheet with Sheet1 as its tab caption.
    Everyone who confuses correlation and causation ends up dead.

  7. #7
    Registered User
    Join Date
    07-10-2018
    Location
    Uk
    MS-Off Ver
    MS365 Version 2102
    Posts
    86

    Re: User form not adding data to sheet

    Thank you for your help all solved

  8. #8
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: User form not adding data to sheet

    Quote Originally Posted by rorya View Post
    If you're not getting an error, then the data is going somewhere. Are you sure you're looking at the correct sheet? Sheet1 is a codename and is not necessarily the sheet with Sheet1 as its tab caption.
    I ran it with SHEET1 and I had another word as the caption. apparently that matters not.

  9. #9
    Registered User
    Join Date
    07-10-2018
    Location
    Uk
    MS-Off Ver
    MS365 Version 2102
    Posts
    86

    Re: User form not adding data to sheet

    Me again!

    I need to stop users entering duplicate information

    How can I change the code so that the User Form checks if the Value already exists in each Column and if it does display a msg box and not allow them to enter a duplicate?
    here is my existing code:

    Option Explicit
    
    Private Sub CommandButton1_Click()
    Private Sub cmdAddTooling_Click()
    Dim wks As Worksheet
    Dim AddNew As Range
    Set wks = Sheet6
    Set AddNew = wks.Range("A65356").End(xlUp).Offset(1, 0)
    
    AddNew.Offset(0, 0).Value = UserForm1.txtLine
    AddNew.Offset(0, 1).Value = UserForm1.txtToolType
    AddNew.Offset(0, 2).Value = UserForm1.txtPartNumber
    AddNew.Offset(0, 3).Value = UserForm1.txtTCNNumber
    AddNew.Offset(0, 4).Value = UserForm1.txtDrawingNumber
    AddNew.Offset(0, 5).Value = UserForm1.txtNumber
    AddNew.Offset(0, 6).Value = UserForm1.txtMaterial
    
    
    
    
    
    End Sub
    
    Private Sub cmdClose_Click()
    Dim iexit As VbMsgBoxResult
    iexit = MsgBox("Are you sure you want to close the Window", vbQuestion + vbYesNo, "Data Entry Form")
    
    If iexit = vbYes Then
    Unload Me
    End If
    
    End Sub
    
    
    Private Sub cmdClearAllFields_Click()
    
    Dim icontrol As Control
    
    For Each icontrol In Me.Controls
    
    If icontrol.Name Like "txt*" Then icontrol = vbNullString
    
    Next
    
    End Sub
    
    Private Sub Workbook_Open()
    frmEmpData.Show
    End Sub
    
    
    
    End Sub
    Many Thanks

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: User form not adding data to sheet

    Do you mean it should check all the columns and not allow the entry at all if any of them are duplicated, or check each column and only disallow each column if it's a duplicate?

  11. #11
    Registered User
    Join Date
    07-10-2018
    Location
    Uk
    MS-Off Ver
    MS365 Version 2102
    Posts
    86

    Re: User form not adding data to sheet

    It should check all columns please and not allow entry if any are duplicated

    Thanks

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: User form not adding data to sheet

    Just FYI the code you posted would never run, as you have put several subroutines inside another one.

    Try this:

    Private Sub cmdAddTooling_Click()
    Dim wks As Worksheet
    Dim AddNew As Range
    Set wks = Sheet6
    Set AddNew = wks.Range("A65356").End(xlUp).Offset(1, 0)
    with application.worksheetfunction
       if .countif(addnew.entirecolumn, me.txtLine) = 0 then
          if .countif(addnew.entirecolumn.offset(, 1), me.txtToolType) = 0 then
             if .countif(addnew.entirecolumn.offset(, 2), me.txtPartNumber) = 0 then
                if .countif(addnew.entirecolumn.offset(, 3), me.txtTCNNumber) = 0 then
                   if .countif(addnew.entirecolumn.offset(, 4), me.txtDrawingNumber) = 0 then
                      if .countif(addnew.entirecolumn.offset(, 5), me.txtNumber) = 0 then
                         if .countif(addnew.entirecolumn.offset(, 6), me.txtMaterial) = 0 then
                             AddNew.Offset(0, 0).Value = me.txtLine
                             AddNew.Offset(0, 1).Value = me.txtToolType
                             AddNew.Offset(0, 2).Value = me.txtPartNumber
                             AddNew.Offset(0, 3).Value = me.txtTCNNumber
                             AddNew.Offset(0, 4).Value = me.txtDrawingNumber
                             AddNew.Offset(0, 5).Value = me.txtNumber
                             AddNew.Offset(0, 6).Value = me.txtMaterial
                          End If
                       End If
                   End If
                End If
            End If
         End If
       End If
    End With
    
    End Sub
    You might want to add a message in an Else clause for each If just to let the user know why the data isn't being added!

  13. #13
    Registered User
    Join Date
    07-10-2018
    Location
    Uk
    MS-Off Ver
    MS365 Version 2102
    Posts
    86

    Re: User form not adding data to sheet

    Could you please give an example of the position of the else clause?

  14. #14
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: User form not adding data to sheet

    You would have one before each End If line, so that you can specify which value is a duplicate.

  15. #15
    Registered User
    Join Date
    07-10-2018
    Location
    Uk
    MS-Off Ver
    MS365 Version 2102
    Posts
    86

    Re: User form not adding data to sheet

    Hi,

    Just tried that but it only returns the last msg box regardless of the duplicate

     If .CountIf(AddNew.EntireColumn.Offset(, 3), Me.txtTCNNumber) = 0 Then
                
                
                
                        If .CountIf(AddNew.EntireColumn.Offset(, 4), Me.txtDrawingNumber) = 0 Then
                        
                        
                                     If .CountIf(AddNew.EntireColumn.Offset(, 5), Me.txtTRSNumber) = 0 Then
                
                                     
                                 
                
                            
                             AddNew.Offset(0, 3).Value = Me.txtTCNNumber
                             AddNew.Offset(0, 4).Value = Me.txtDrawingNumber
                             AddNew.Offset(0, 5).Value = Me.txtTRSNumber
                             
                            
                             
                                ElseIf .CountIf(AddNew.EntireColumn.Offset(, 5), Me.txtTRSNumber) = 1 Then
                                
                                MsgBox "This TRS Number is already in use!"
                            
                            End If
                            
                            ElseIf .CountIf(AddNew.EntireColumn.Offset(, 4), Me.txtDrawingNumber) = 1 Then
                        
                             MsgBox "This Drawing Number is already in use!"
                             
                       End If
                       
                       Else
                        MsgBox "This TCN Number is already in use!"
                End If
          
       
    End With
    
    End Sub
    Any ideas?

  16. #16
    Registered User
    Join Date
    07-10-2018
    Location
    Uk
    MS-Off Ver
    MS365 Version 2102
    Posts
    86

    Re: User form not adding data to sheet

    I have got this working now however I didn't explain what I needed to achieve very well:

    If a duplicate is found in the columns then I would like an error message as well as not being able to enter any non duplicated information into the row

    Also I would like the default value in the TCNNumber input box to default to +1 of the the highest number in that column

    Thanks for all your help

  17. #17
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,356

    Re: User form not adding data to sheet

    How about this.

    Private Sub cmdAddTooling_Click()
        Dim wks As Worksheet, AddNew As Range
        Dim myarr, i As Long, msg As String
        
        Set wks = Sheet6
        Set AddNew = wks.Range("A" & wks.Rows.Count).End(xlUp).Offset(1)
    
        myarr = Array(Me.txtLine, Me.txtToolType, Me.txtPartNumber, Me.txtTCNNumber, Me.txtDrawingNumber, Me.txtNumber, Me.txtMaterial)
        
        For i = 0 To 6
            If Application.CountIf(AddNew.EntireColumn.Offset(, i), myarr(i)) <> 0 Then msg = msg & "," & myarr(i)
        Next
        If msg <> "" Then MsgBox "These textboxes hold duplicate : " & Mid(msg, 2): Exit Sub
    
        AddNew.Offset(0, 0).Value = Me.txtLine
        AddNew.Offset(0, 1).Value = Me.txtToolType
        AddNew.Offset(0, 2).Value = Me.txtPartNumber
        AddNew.Offset(0, 3).Value = Me.txtTCNNumber
        AddNew.Offset(0, 4).Value = Me.txtDrawingNumber
        AddNew.Offset(0, 5).Value = Me.txtNumber
        AddNew.Offset(0, 6).Value = Me.txtMaterial
    
    End Sub

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

    Re: User form not adding data to sheet

    How about uploading your workbook ??????????
    Sixteen posts and barely one step forward.
    torachan.

  19. #19
    Registered User
    Join Date
    12-06-2020
    Location
    Forl', Italy
    MS-Off Ver
    Office 2019
    Posts
    20

    Re: User form not adding data to sheet

    Try this:

    Private Sub cmdAddTooling_Click()
    Dim AddNew As Range

    Set AddNew = [Sheet1!A1].End(xlDown)
    AddNew(2, 1) = "txtPartNumber"
    AddNew(2, 2) = "txtTool"
    AddNew(2, 3) = "txtDrawing"
    AddNew(2, 4) = "txtNumber"

    End Sub

  20. #20
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,356

    Re: User form not adding data to sheet

    Did you try the code provided in Post#16?

+ 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. popped a warning message to before adding the data into excel sheet from user form
    By limhuihui in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-03-2018, 10:19 PM
  2. [SOLVED] Adding data from user form to email
    By echoz in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-04-2017, 10:44 AM
  3. User Form Data Entry Adding a TimeStamp
    By caltman242 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-14-2015, 09:15 AM
  4. [SOLVED] Restricting the user form to adding to excel sheet
    By shiftyspina in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-24-2013, 07:41 AM
  5. [SOLVED] User Form not adding data
    By JO505 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 02-07-2013, 01:21 PM
  6. Adding "All Borders" with a User Form (Similar to Data Form)
    By kgreave1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-26-2012, 01:57 PM
  7. Adding data to sheet with user form
    By Jay in forum Excel General
    Replies: 1
    Last Post: 06-08-2005, 11:05 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