Adjusting code transfer data from combo box & textbox into userform to sheet

Closed
abdelfatah_0230 Posts 73 Registration date Thursday July 18, 2019 Status Member Last seen July 23, 2022 - Updated on Nov 3, 2019 at 05:04 AM
 Facebook - Nov 21, 2019 at 04:03 PM
Hello,



i would help adjusting this code it doesn't work it gives me error when i transfer data to sheet
i want to begins transfer data from a23:g23 of course automatically when i fill a new data insert a new row under a23:g23 with the same format
Private Sub CommandButton1_Click()
Dim My_sh As Worksheet
Set My_sh = Worksheets("sheet1")
Dim Lastrow As Integer
Dim i% Application.ScreenUpdating = False
With My_sh Lastrow = .Cells(Rows.Count, 1).End(3).Row + 1
.Range(.Cells(Lastrow - 1, 1), .Cells(Lastrow - 1, 7)).Copy
.Cells(Lastrow, 1).PasteSpecial Paste:=xlPasteFormats
For i = 1 To 7
.Cells(Lastrow, i).Value = Me.Controls("TextBox" & "combobox" & i)
Me.Controls("TextBox" & "combobox" & i) = ""
Next
End With
Application.ScreenUpdating = True
Application.CutCopyMode = False
MsgBox "ok"
end sub


this code gives me the error





and this is my userform :


and this is my sheet1:
Related:

1 response

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 552
Nov 5, 2019 at 11:41 AM
Hi Abdel,

You are getting an error because you have TextBox# and ComboBox#, but not a TextBoxComboBox#.

You could change:
.Cells(Lastrow, i).Value = Me.Controls("TextBox" & "combobox" & i)
Me.Controls("TextBox" & "combobox" & i) = ""

into:
.Cells(Lastrow, i).Value = Me.Controls("TextBox" & i) & " " & Me.Controls("ComboBox" & i)
Me.Controls("TextBox" & i) = vbnullstring
Me.Controls("ComboBox" & i) = vbnullstring

Best regards,
Trowa
0
abdelfatah_0230 Posts 73 Registration date Thursday July 18, 2019 Status Member Last seen July 23, 2022
Nov 5, 2019 at 02:43 PM
it gives me the same error
i attach my file
https://ufile.io/u2xzo9cy
0
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 552
Nov 11, 2019 at 11:52 AM
Hi Abdel,

When the code errors out, place your cursor over the yellow line above the "i". It should tell you that the current value for i = 7. That means that 1 to 6 went ok. So I checked TextBox7 and ComboBox7. Which showed the reason for the error: you don't have a ComboBox7.

Best regards,
Trowa
0
abdelfatah_0230 Posts 73 Registration date Thursday July 18, 2019 Status Member Last seen July 23, 2022
Nov 11, 2019 at 01:24 PM
you are right but despite correcting your note it is still problem it only transfer describe the brand in combobox1 and ignore the rest of me.controls also it begins from row40 not 23 i attache my image
0
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 552
Nov 12, 2019 at 11:49 AM
Hi Abdel,

Row 40 is the first empty row of column A from the bottom up, which is what this part of the code does:
Cells(Rows.Count, 1).End(3).Row + 1

And since that cell is merged, only the value in column A is shown.

Best regards,
Trowa
0
abdelfatah_0230 Posts 73 Registration date Thursday July 18, 2019 Status Member Last seen July 23, 2022
Nov 12, 2019 at 01:47 PM
so how i can enforce the code runs from row 23 under topics item, brand ,type...etc
by the way the cells rows from 23:24 not emerged cells
0