Atiqul Haque
New Member
- Joined
- Dec 13, 2020
- Messages
- 45
- Office Version
- 2016
- Platform
- Windows
Dear All,
Into a table of my data sheet when i transfer data, serial number (1) repeats in each rows. Can anyone advice me where is the problem in my code:
Option Explicit
Private Sub CommandButton1_Click()
Dim rng As Range
Set rng = ActiveSheet.ListObjects("Table1").Range
Dim LastRow As Long
Dim erow As Long
erow = [Counta(Test!A:A)] + 1
LastRow = rng.Find(What:="*", _
After:=rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
rng.Parent.Cells(LastRow + 1, 1).Value = erow - 1
rng.Parent.Cells(LastRow + 1, 2).Value = txtDate.Value
rng.Parent.Cells(LastRow + 1, 3).Value = txtName.Value
rng.Parent.Cells(LastRow + 1, 4).Value = cmbSex.Value
rng.Parent.Cells(LastRow + 1, 5).Value = [Text(Now(), "DD-MM-YYYY HH:MM:SS")]
'Reset the userform
txtDate.Value = ""
txtName.Value = ""
cmbSex.Value = ""
End Sub
Into a table of my data sheet when i transfer data, serial number (1) repeats in each rows. Can anyone advice me where is the problem in my code:
Option Explicit
Private Sub CommandButton1_Click()
Dim rng As Range
Set rng = ActiveSheet.ListObjects("Table1").Range
Dim LastRow As Long
Dim erow As Long
erow = [Counta(Test!A:A)] + 1
LastRow = rng.Find(What:="*", _
After:=rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
rng.Parent.Cells(LastRow + 1, 1).Value = erow - 1
rng.Parent.Cells(LastRow + 1, 2).Value = txtDate.Value
rng.Parent.Cells(LastRow + 1, 3).Value = txtName.Value
rng.Parent.Cells(LastRow + 1, 4).Value = cmbSex.Value
rng.Parent.Cells(LastRow + 1, 5).Value = [Text(Now(), "DD-MM-YYYY HH:MM:SS")]
'Reset the userform
txtDate.Value = ""
txtName.Value = ""
cmbSex.Value = ""
End Sub