When i try to add data to my table from a userform data entry form - it goes like this ( please look at the screenshot)
some of my information goes on a row and others go to another row
please help to solve this problem
my code is
please help to solve this problem
my code is
VBA Code:
Private Sub CommandButton1_Click()
Dim wks As Worksheet
Dim addnew As Range
Dim f As Range
Dim r As Range
Set wks = Sheet1
Set r = wks.Range("B:B").Find(TextBox2.Value, , xlValues, xlWhole)
If Not r Is Nothing Then
MsgBox "Website Name Already exists: " & TextBox2.Value
Exit Sub
End If
'Prevent duplicates in column H
Set f = wks.Range("A:A").Find(TextBox1.Value, , xlValues, xlWhole)
If Not f Is Nothing Then
MsgBox "Publisher House Name Already exists: " & TextBox1.Value
Exit Sub
End If
'change the number for the number of controls on the userform
cNum = 27
'add the data to the selected worksheet
Set addnew = wks.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
For x = 1 To cNum
addnew = Me.Controls("TextBox" & x).Value
Set addnew = addnew.Offset(0, 1)
Next
'clear the values in the userform
For x = 1 To cNum
Next
'communicate the results
MsgBox "The values have been sent to the " & sht & " Publisher House Sheet"
Dim arrItems()
Dim cnt As Long
Dim pro As Long
For pro = 0 To TextBox7.ListCount - 1
If TextBox7.Selected(pro) Then
ReDim Preserve arrItems(cnt)
arrItems(cnt) = TextBox7.List(pro)
cnt = cnt + 1
End If
Next pro
If cnt > 0 Then
Sheet1.Range("G" & Rows.Count).End(xlUp).Value = Join(arrItems, "|")
End If
Dim arrItems1()
Dim op As Long
Dim om As Long
For om = 0 To TextBox6.ListCount - 1
If TextBox6.Selected(om) Then
ReDim Preserve arrItems1(op)
arrItems1(op) = TextBox6.List(om)
op = op + 1
End If
Next om
If op > 0 Then
Sheet1.Range("F" & Rows.Count).End(xlUp).Value = Join(arrItems1, "|")
End If
End Sub