+ Reply to Thread
Results 1 to 9 of 9

Code to copy from userform to logsheet not working, no error messages

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-12-2009
    Location
    Hendersonville, TN
    MS-Off Ver
    Excel 2010
    Posts
    113

    Code to copy from userform to logsheet not working, no error messages

    Hi everyone.

    Could someone please take a look at this code and tell me what I need to change to make it function. Background: Userform has info put into fields. After it is complete, user hit submit button which is tied to this:

    Private Sub CMB_Submit_Click()
       Dim rw As Long    'next available row
     
       With Sheets("EEG Log")
     
          'get the next avialable row in Sheet1
          rw = .Range("A" & .Rows.Count).End(xlUp).Row + 1
     
          'put the text box values in this row
          .Range("A" & rw).Value = TB_Date.Value
          .Range("B" & rw).Value = CMB_Employee.Value
          .Range("C" & rw).Value = Combobox1.Value
          .Range("D" & rw).Value = CMB_Absent.Value
          .Range("E" & rw).Value = TB_POINT.Value
          .Range("F" & rw).Value = TB_Description.Text
          .Range("G" & rw).Value = Combo_Charge.Text
          
               
       End With
       
       Dim resp As Integer
    resp = MsgBox("Data submited to log." & vbCrLf & "Do you have another entry for this workgroup?", vbYesNo)
    If resp = vbYes Then
    
    With Sheets("EEG Log")
       
       
       CMB_Absent.Value = ""
       CMB_Employee.Value = ""
       Combobox1.Value = ""
       TB_Description.Text = ""
       TB_POINT.Value = ""
       Combo_Charge.Value = ""
       
      End With
      End If
      
      
    If resp = vbNo Then
        CMB_Absent.Value = ""
       CMB_Employee.Value = ""
       Combobox1.Value = ""
       TB_Description.Text = ""
       TB_POINT.Value = ""
       Combo_Charge.Value = ""
    
    ThisWorkbook.Save
       
        UF_EEGOCC.Hide
        UF_MANJP.Show
        
        
     
         End If
           
         End Sub
    I don't see any errors on this, but it is not copying the data to the logsheet.

    Any ideas?


    Thanks for your help.

    Patrick

  2. #2
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Code to copy from userform to logsheet not working, no error messages

    I don't see a problem with the code, though I have a few suggestions for cleaning it up a bit (see below). Try putting a debug stop at the beginning and step through it. Make sure it's putting the data where it should and find out what's happening to it.

        End With
    
        CMB_Absent.Value = ""
        CMB_Employee.Value = ""
        Combobox1.Value = ""
        TB_Description.Text = ""
        TB_POINT.Value = ""
        Combo_Charge.Value = ""
    
        If MsgBox("Data submited to log." & vbCrLf & "Do you have another entry for this workgroup?", vbYesNo) = vbNo Then
            ThisWorkbook.Save
            UF_EEGOCC.Hide
            UF_MANJP.Show
        End If

  3. #3
    Forum Contributor
    Join Date
    05-12-2009
    Location
    Hendersonville, TN
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: Code to copy from userform to logsheet not working, no error messages

    Thanks for cleaning up the code for me Nate. I am still trying to figure out why it is not working. It seemed to quit around the same time I formatted the sheet as a table. Perhaps that has something to do with it.


    Patrick

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Code to copy from userform to logsheet not working, no error messages

    Patrick

    Are you sure the data isn't going onto the sheet?

    It could be but not going where you expect/want it to, take a look at the value of rw when you step through the code with F8.
    If posting code please use code tags, see here.

  5. #5
    Forum Contributor
    Join Date
    05-12-2009
    Location
    Hendersonville, TN
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: Code to copy from userform to logsheet not working, no error messages

    I am not quite sure how this happened, but my data was getting copied to the sheet, just starting at row 1000. I erased the data and tried again and it seems to copy fine. However, I have issues elsewhere. I am now getting a Type Mismatch error that is pointing back to another bit of code I have going. I am at a loss. When I fill out the userform and click the control attached to this:
    Private Sub CMB_Submit_Click()
       Dim rw As Long    'next available row
     
       With Sheets("EEG_Log")
     
          'get the next avialable row in Sheet1
          rw = .Range("A" & .Rows.Count).End(xlUp).Row + 1
     
          'put the text box values in this row
          .Range("A" & rw).Value = TB_Date.Value
          .Range("B" & rw).Value = CMB_Employee.Value
          .Range("C" & rw).Value = Combobox1.Value
          .Range("D" & rw).Value = TB_POINT.Value
          .Range("E" & rw).Value = TB_Description.Text
          .Range("F" & rw).Value = Combo_Charge.Text
          
               
       End With
       
       Dim resp As Integer
    resp = MsgBox("Data submited to log." & vbCrLf & "Do you have another entry?", vbYesNo)
    If resp = vbYes Then
    
    With Sheets("EEG_Log")
       
       
       Combo_Charge.Text = ""
       CMB_Employee.Value = ""
       Combobox1.Value = ""
       TB_Description.Text = ""
       TB_POINT.Value = ""
        
      End With
      End If
      
      
    If resp = vbNo Then
    
    ThisWorkbook.Save
       
         UF_EEGOCC.Hide
        
        UF_MANJP.Show
        
        
     
         End If
         
       End Sub
    It seems to complete and gets me to the message box. Clicking yes will error out Type Mismatch on this code:

    Private Sub Combobox1_Change()
    
    On Error Resume Next
        
        Dim Frm1 As String
            
       Frm1 = Application.VLookup(Me.Combobox1.Value, Sheets("Data_Sheet").Range("F2:G8"), 2, False)               
       
     TB_POINT = Frm1
            
        
    End Sub

    Any ideas on what I need to do differently?


    Patrick

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Code to copy from userform to logsheet not working, no error messages

    Patrick

    How have you populated Combobox1?

  7. #7
    Forum Contributor
    Join Date
    05-12-2009
    Location
    Hendersonville, TN
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: Code to copy from userform to logsheet not working, no error messages

    I have a named range "Infraction" on the Data_Sheet. I have is listed in the rowsource for my userform. The range does match the cells F2:G8.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Code to copy from userform to logsheet not working, no error messages

    There's no need to use VLookUp then.
    Private Sub Combobox1_Change()
    Dim idx As Long
    
        idx = Combobox1.ListIndex
    
        If idx = -1 Then Exit Sub ' exit sub if nothing selected
    
        TB_POINT.Value = ComboBox1.List(idx, 1)
        
    End Sub
    Last edited by Norie; 12-12-2013 at 03:23 PM.

  9. #9
    Forum Contributor
    Join Date
    05-12-2009
    Location
    Hendersonville, TN
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: Code to copy from userform to logsheet not working, no error messages

    Brilliant! Thank you so much Norie. Your code did the trick.

    Patrick

+ 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] Error Handling: Creating code to display error messages
    By Student1990 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-01-2013, 02:21 PM
  2. VBA code to copy Outlook Messages to excel
    By Ironman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-15-2011, 04:40 PM
  3. Turn Off Error Messages While Typing Code
    By yawnzzzz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-03-2008, 11:18 AM
  4. error messages from check box code...
    By lottesfog in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-25-2007, 01:53 AM
  5. error messages-Is there a way to show error messages
    By hans in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-02-2006, 12:45 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