Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Transfering Data From Userform To Sheet Under Relevant Column And Row

  1. #1
    Senior Member
    Join Date
    Mar 2013
    Posts
    107
    Rep Power
    12

    Transfering Data From Userform To Sheet Under Relevant Column And Row

    Hi

    I need some help please with the code transferring data from userform to sheet.The sheet will be protected == password is 1357
    The userform looks at set Number and then finds it in the sheet and transfers the data.

    Thanks

    Paul
    Attached Files Attached Files

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    I've made some modifications to your sheet. Notice the rngToCopy named range. You can move it around if required, but just keep whatever format you need. Also, revisions in the code are as follows

    Code:
    Private Sub UserForm_Initialize()
    
        Dim i As Long
    
    '.
    '.
    '.
    '.
    '.
    
        With Worksheets("LENTICULAR-MEMBRANES")
            .Unprotect Password:="1357"
            .Protect UserInterfaceOnly:=True, Password:="1357"
        End With
    
    End Sub
    
    Private Sub CommandButton1_Click()
       
        Dim lngCol As Long
        Dim ctl As Object
        For Each ctl In Me.Controls
            If ctl.Tag <> vbNullString Then
                If ctl.Value = vbNullString Then MsgBox ctl.Tag: ctl.SetFocus: Exit Sub
            End If
        Next
        With Sheets("LENTICULAR-MEMBRANES")
        lngCol = .Rows("3:3").Find(What:="SET " & ComboBox2.Text, LookAt:=xlWhole).Column
           With .Cells(.Rows.Count, lngCol).End(xlUp).Offset(1).Cells(1)
                Sheets("LENTICULAR-MEMBRANES").Range("rngToCopy").Copy .Cells(1)
                .Resize(6).Value = Application.Transpose(Array("DATE", "LENTICULARS CHANGED", "MEMBRANES CHANGED", "VARIETY", "VOLUME", TextBox2.Text))
                .Offset(, 1).Resize(5) = Application.Transpose(Array(ComboBox1.Value, ComboBox3.Value, ComboBox4.Value, ComboBox5.Value, TextBox1.Text))
            End With
        End With
        
        For Each ctl In Me.Controls
            If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then ctl.Value = vbNullString
        Next
        
    End Sub
    Attached Files Attached Files
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Senior Member
    Join Date
    Mar 2013
    Posts
    107
    Rep Power
    12
    I`ve changed the layout to the data capture sheet.I have set up the sheet so data goes down the sheet for each set.With the userform can it look for the heading for the set and place the information going down the sheet.If I select C2 in the Userform Lenticular set then it places that info into C2 data capture sheet

    Thanks

    Paul
    Attached Files Attached Files

  4. #4
    Senior Member
    Join Date
    Mar 2013
    Posts
    107
    Rep Power
    12
    This is altered to a set per sheet.On the userform depending which set selected depends on which sheet data goes...if C1 selected then data goes to C1 sheet etc..etc..

    Paul
    Attached Files Attached Files

  5. #5
    Senior Member
    Join Date
    Mar 2013
    Posts
    107
    Rep Power
    12
    bump

  6. #6
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Here's the revised code

    Code:
    Private Sub CommandButton1_Click()
       
        Dim lngCol As Long
        Dim ctl As Object
        For Each ctl In Me.Controls
            If ctl.Tag <> vbNullString Then
                If ctl.Value = vbNullString Then MsgBox ctl.Tag: ctl.SetFocus: Exit Sub
            End If
        Next
        With Sheets("LENTICULAR-MEMBRANES")
        lngCol = .Rows("2:2").Find(What:="SET " & ComboBox2.Text, LookAt:=xlWhole).Column
           With .Cells(.Rows.Count, lngCol).End(xlUp).Offset(1)
                .Resize(, 6) = Array(ComboBox1.Value, ComboBox3.Value, ComboBox4.Value, ComboBox5.Value, TextBox1.Text, TextBox2.Text)
            End With
        End With
        
        For Each ctl In Me.Controls
            If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then ctl.Value = vbNullString
        Next
        
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  7. #7
    Senior Member
    Join Date
    Mar 2013
    Posts
    107
    Rep Power
    12
    Thanks

    I get an error - subscript out of range

    I think it may have to do with the sheet names....

    I changed the sheet names in code but still error

    Thanks

    Paul
    Attached Files Attached Files

  8. #8
    Moderator
    Join Date
    Jul 2012
    Posts
    156
    Rep Power
    13
    Makes sence. Where is this sheet.
    Code:
        With Worksheets("LENTICULAR-MEMBRANES")
            .Unprotect Password:="1357"
            .Protect UserInterfaceOnly:=True, Password:="1357"
        End With
    Also you use the Tag-property to check for empty objects but in not one object you've filled in the Tag-property. In this case this will never work properly.

  9. #9
    Senior Member
    Join Date
    Mar 2013
    Posts
    107
    Rep Power
    12
    Thanks

    That sheet was removed...there are 5 sheets C1,C2,C3,C4,C5....I did enter these sheets in place of the LENTICULAR-MEMBRANES but it still gave error

    I will fill in the Tag property

    I will see how this goes

    Paul

  10. #10
    Moderator
    Join Date
    Jul 2012
    Posts
    156
    Rep Power
    13
    But that part of code is still in your Userform_Initialize procedure so it will always throw an error when starting-up your UF.
    The way you filled in your sheets is also wrong. I suppose you will have to use the value of your Lenticular set -object to write to the correct sheet.
    It will become something like this

    Code:
        With Sheets(ComboBox2.Value)
        lngCol = .Rows("2:2").Find(What:="SET " & ComboBox2.Text, LookAt:=xlWhole).Column
           With .Cells(.Rows.Count, lngCol).End(xlUp).Offset(1)
                .Resize(, 6) = Array(ComboBox1.Value, ComboBox3.Value, ComboBox4.Value, ComboBox5.Value, TextBox1.Text, TextBox2.Text)
            End With
        End With
    Last edited by bakerman; 08-08-2013 at 11:52 AM.

Similar Threads

  1. Replies: 30
    Last Post: 07-19-2013, 07:52 AM
  2. Replies: 8
    Last Post: 07-01-2013, 03:52 PM
  3. Group Pivot Data Based On Row Values In One Column
    By mrmmickle1 in forum Excel Help
    Replies: 10
    Last Post: 10-09-2012, 11:46 PM
  4. Copy Row To A New Sheet If A Value Found In Adjacent Column
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 4
    Last Post: 08-17-2012, 05:42 PM
  5. Finding Last Used Row or Column In Excel Sheet
    By Rasm in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 04-14-2011, 03:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •