Hi shido
Try this.
Private Sub cmdClose_Click()
'Close the userform
Unload Me
'http://www.onlinepclearning.com/excel-vba-userform-vlookup/
End Sub
Private Sub cmdSend_Click()
'Dim the variables
Dim cNum As Integer
Dim X As Integer
Dim nextrow As Range
'change the number for the number of controls on the userform
cNum = 6
Set nextrow = Worksheets("IQuery").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
For X = 1 To cNum
nextrow = Me.Controls("Reg" & X).Value
Set nextrow = nextrow.Offset(0, 1)
Next
With Sheets("Database")
Dim lastrow As Long
lastrow = .Range("a" & .Rows.Count).End(xlUp).Row
' Sheets("Database").Activate
.Cells(lastrow + 1, "a").Value = Reg1
.Cells(lastrow + 1, "b").Value = Reg2
.Cells(lastrow + 1, "c").Value = Reg3
.Cells(lastrow + 1, "d").Value = Reg4
.Cells(lastrow + 1, "e").Value = Reg5
.Cells(lastrow + 1, "f").Value = Reg6
End With
MsgBox "The data has been sent"
'Clear the controls
cNum = 6
For X = 1 To cNum
Me.Controls("Reg" & X).Value = ""
Set nextrow = nextrow.Offset(0, 1)
Next
End Sub
'Private Sub Reg1_AfterUpdate()
' 'Check to see if value exists
' If WorksheetFunction.CountIf(Worksheets("Database").Range("A:A"), Me.Reg1.Value) = 0 Then
' 'MsgBox "This is an incorrect ID"
'
' Dim lastrow As Long
' lastrow = Sheets("Database").Range("a" & Rows.Count).End(xlUp).Row
' Sheets("Database").Activate
'
' Cells(lastrow + 1, "a").Value = Reg1
' Cells(lastrow + 1, "b").Value = Reg2
' Cells(lastrow + 1, "c").Value = Reg3
' Cells(lastrow + 1, "d").Value = Reg4
' Cells(lastrow + 1, "e").Value = Reg5
' Cells(lastrow + 1, "f").Value = Reg6
'
' Sheets("IQuery").Activate
'
' Else
'
' With Me
' .Reg2 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Worksheets("Database").Range("Lookup"), 2, 0)
' .Reg3 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Worksheets("Database").Range("Lookup"), 3, 0)
' .Reg4 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Worksheets("Database").Range("Lookup"), 4, 0)
' .Reg5 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Worksheets("Database").Range("Lookup"), 5, 0)
' .Reg6 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Worksheets("Database").Range("Lookup"), 6, 0)
' End With
'
' End If
'
'End Sub
Bookmarks