Hello
I'm confused why this problem occures!
I modified the code by add two columns in B,C for sheets result,result1 (becuase I will fill by another macro )
so the code should start from column D from row2 . it 's ok for RESULT sheet
but RESULT1 sheet will copy starting from row13 (should be from row2) I no know why ! . the orginal file (first) will work without any problem , but I cut part of my project still copy starting from row13 for RESULT1 sheet. I still no know what's the reason !
for me this mystery .
short words : just start copying from row 2 for column D and ignore copy ITEMS from userform as I disabled because I want populating date in column A when fill column D automatically(no need ITEMS from userform)
Private Sub CommandButton5_Click()
Dim i As Long
Dim sheetname As String
Dim lRw As Long ' for Last Row
' count to 2 not 4 (since there are only two buttons at present)
For i = 1 To 2
With Me.Controls("OptionButton" & i)
If .Value Then sheetname = .Caption: Exit For
End With
Next i
' check a option was selected
If sheetname = "" Then
MsgBox "Please select an option button first"
Exit Sub
End If
With Worksheets(sheetname)
' loop down UserForm controls
For i = 1 To 11
' see if a Code was set
If Me.Controls("ComboBox" & i + 1).Text <> "" Then
'if Code set, find last row in B
' change copy lastrow from B to D
lRw = .Cells(Rows.Count, 4).End(xlUp).Row
' no need this line I replace with date by I put procedure in sheet module when 'fill column D
'.Cells(lRw + 1, 1).Value = Me.Controls("TextBox" & i)
' change copying data from D:J instead of A:H
.Cells(lRw + 1, 4).Value = Me.Controls("ComboBox" & i + 1)
.Cells(lRw + 1, 5).Value = Me.Controls("ComboBox" & i + 12)
.Cells(lRw + 1, 6).Value = Me.Controls("ComboBox" & i + 23)
.Cells(lRw + 1, 7).Value = Me.Controls("ComboBox" & i + 34)
.Cells(lRw + 1, 8).Value = Me.Controls("TextBox" & i + 11)
.Cells(lRw + 1, 9).Value = Me.Controls("TextBox" & i + 22)
.Cells(lRw + 1, 10).Value = Me.Controls("TextBox" & i + 33)
' clear Qty and Total controls (at least)
Me.Controls("TextBox" & i + 11) = ""
Me.Controls("TextBox" & i + 33) = ""
Else
' do nothing
End If
Next i
End With
End Sub
I hope anybody has answer about this problem .