Data from userform only submitting to 2 columns?

jacob1234

New Member
Joined
Aug 16, 2016
Messages
37
Hi All,

Hopefully somebody can help me with this one, I have a userform that is submitting data to the next empty row of columns "T:AB" but the code is only submitting data to columns T and U, could anyone please help me to find out why?


Thanks in advance


Jacob.


Code:
Private Sub CommandButton7_Click()
Dim LastRow1 As Long, lngIndex1 As Long, ws As Worksheet

    
    
        
    Dim OutApp As Object
    Dim OutMail As Object
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    
    With OutMail
        .To = ComboBox7.Value
        .CC = ""
        .BCC = ""
        .Subject = "CAOOS" & " " & MonthView1.Value & " " & "Unique ID Number:" & " " & Label4.Caption
        .HTMLBody = "Hi" & " " & ComboBox7.Value & "<br>" & "<br>" & "You have a new Customer Acceptance form to fill out." & "<br>" & "<br>" & "This has been submitted by:" & " " & Label1.Caption & "<br>" & "<br>" & "To view new submission" & " " & "<A HREF=""file://" & ActiveWorkbook.FullName & """>Click Here</A>" & "<br>" & "<br>" & "<br>" & "<br>" & "Unique ID Number:" & " " & Label4.Caption
  
        
    .Send   'or use .Display
        
    Set OutMail = Nothing
    Set OutApp = Nothing
    
    
    MsgBox "This row has now been updated", vbOKOnly, "Success"
    
        End With
        
        
        
        
    LastRow1 = Range("S" & Rows.Count).End(xlUp).Row
    lngIndex1 = Me.ListBox3.ListIndex
    Set ws = Sheets("DATABASE")
    
    
    ws.Range("T" & LastRow1).Cells(lngIndex1 + 1) = UserForm1.TextBox9.Value
    ws.Range("U" & LastRow1).Cells(lngIndex1 + 1) = UserForm1.MonthView2.Value
    ws.Range("V" & LastRow1).Cells(lngIndex1 + 1) = UserForm1.TextBox10.Value
    ws.Range("W" & LastRow1).Cells(lngIndex1 + 1) = UserForm1.TextBox14.Value
    ws.Range("X" & LastRow1).Cells(lngIndex1 + 1) = UserForm1.TextBox15.Value
    ws.Range("Y" & LastRow1).Cells(lngIndex1 + 1) = UserForm1.TextBox16.Value
    ws.Range("Z" & LastRow1).Cells(lngIndex1 + 1) = UserForm1.TextBox17.Value
    ws.Range("AA" & LastRow1).Cells(lngIndex1 + 1) = UserForm1.ComboBox6.Value
    ws.Range("AB" & LastRow1).Cells(lngIndex1 + 1) = UserForm1.TextBox18.Value
        
    
    UserForm1.Hide
    
    
    
    
End Sub
 
I am a little confused by your construction... why are you establishing a Range (column letter followed by LastRow) and then specifying those Cell offsets from it... is that really what you want to do? What cells are you actually trying to put values into?


My aim is for users to select a row from a listbox3 that has already been inputted into the sheet and basically add another column of data into that listbox. So for data I enter into Userform1.textbox9 I want it to submit to the row I have selected in the listbox and column T which currently has no data? - trying to submit values to columns T,U,V,W,X,Y,Z,AA,AB

Thanks Again

Jacob
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
My aim is for users to select a row from a listbox3 that has already been inputted into the sheet and basically add another column of data into that listbox. So for data I enter into Userform1.textbox9 I want it to submit to the row I have selected in the listbox and column T which currently has no data? - trying to submit values to columns T,U,V,W,X,Y,Z,AA,AB
But which row... LastRow or lngIndex1+1?
 
Upvote 0
lngIndex+1 which is the listindex of listbox3 ?
Then I am thinking the code snippet you posted should probably look like this instead...
Code:
LastRow = Range("A" & Rows.Count).End(xlUp).Row + 1
lngIndex = ListBox3.ListIndex
Set ws = Sheets("DATABASE")

ws.Cells(lngIndex + 1, "T") = UserForm1.TextBox9.Value
ws.Cells(lngIndex + 1, "U") = UserForm1.MonthView2.Value
ws.Cells(lngIndex + 1, "V") = UserForm1.TextBox10.Value
ws.Cells(lngIndex + 1, "W") = UserForm1.TextBox14.Value
ws.Cells(lngIndex + 1, "X") = UserForm1.TextBox15.Value
ws.Cells(lngIndex + 1, "Y") = UserForm1.TextBox16.Value
ws.Cells(lngIndex + 1, "Z") = UserForm1.TextBox17.Value
ws.Cells(lngIndex + 1, "AA") = UserForm1.ComboBox6.Value
ws.Cells(lngIndex + 1, "AB") = UserForm1.TextBox18.Value
 
Upvote 0
Then I am thinking the code snippet you posted should probably look like this instead...
Code:
LastRow = Range("A" & Rows.Count).End(xlUp).Row + 1
lngIndex = ListBox3.ListIndex
Set ws = Sheets("DATABASE")

ws.Cells(lngIndex + 1, "T") = UserForm1.TextBox9.Value
ws.Cells(lngIndex + 1, "U") = UserForm1.MonthView2.Value
ws.Cells(lngIndex + 1, "V") = UserForm1.TextBox10.Value
ws.Cells(lngIndex + 1, "W") = UserForm1.TextBox14.Value
ws.Cells(lngIndex + 1, "X") = UserForm1.TextBox15.Value
ws.Cells(lngIndex + 1, "Y") = UserForm1.TextBox16.Value
ws.Cells(lngIndex + 1, "Z") = UserForm1.TextBox17.Value
ws.Cells(lngIndex + 1, "AA") = UserForm1.ComboBox6.Value
ws.Cells(lngIndex + 1, "AB") = UserForm1.TextBox18.Value



Thanks Rick - I have tried this code but it isn't working correctly. The code puts data only into columns T and U and submits to the row above the listbox selected row?
 
Upvote 0
Thanks Rick - I have tried this code but it isn't working correctly. The code puts data only into columns T and U and submits to the row above the listbox selected row?




Hi All, hoping to get this problem solved today - any more ideas?

Thanks for all the help so far!
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top