Hi all
Can someone help me with the following issue:
I have written a successful routine on the userform to find the last entry. I want then to go to the previous record until the user finds the one he/she wants and also be able to return to previous. I have separate buttons for previous and next but the find last will not conect with them:
The findlast code that works is:
Below are the previous and next codes that work, but when I select the find last the codes take me to the first record and then scroll from the beginning of the records:
So to be clear what I am trying to achieve is that when the 'Find Last Record Code' shows the last record, the previous and next buttons will allow movement through the records FROM the Last Found Record. I tried a 'GoToRecord' button but it doesn't work either.
Here is an image of the user form:
Any help appreciated.
Subbie
Can someone help me with the following issue:
I have written a successful routine on the userform to find the last entry. I want then to go to the previous record until the user finds the one he/she wants and also be able to return to previous. I have separate buttons for previous and next but the find last will not conect with them:
The findlast code that works is:
Code:
Private Sub CMDLast_Click()
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Dim ws As Worksheet
Dim i As Long
Set ws = ThisWorkbook.Sheets("MasterTransactions")
With ws
i = .Rows.Count
lstdt = .Range("A" & i).End(xlUp).value
lstdt1 = .Range("B" & i).End(xlUp).value
lstdt2 = .Range("C" & i).End(xlUp).value
lstdt3 = .Range("D" & i).End(xlUp).value
lstdt4 = .Range("E" & i).End(xlUp).value
lstdt5 = .Range("F" & i).End(xlUp).value
lstdt6 = .Range("G" & i).End(xlUp).value
Me.DateInput = lstdt
Me.UserPayeeNm = lstdt1
Me.UserPayeeGrp = lstdt2
Me.Ammt = lstdt3
Me.Method = lstdt4
Me.ChqRefNo = lstdt5
Me.EntryType = lstdt6
End With
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
Code:
'Next record code
Private Sub CMDNext_Click()
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Dim LastRow As Long
LastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).row
If currentrow = LastRow Then
MsgBox "you are in the last row! No more data."
Exit Sub
End If
currentrow = currentrow + 1
DateInput = Cells(currentrow, 1)
UserPayeeNm = Cells(currentrow, 2)
UserPayeeGrp = Cells(currentrow, 3)
Ammt = Cells(currentrow, 4)
Method = Cells(currentrow, 5)
ChqRefNo = Cells(currentrow, 6)
EntryType = Cells(currentrow, 7)
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
'Next record code end
'Previous record code
Private Sub CMDPrev_Click()
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
If currentrow = 2 Then
MsgBox "You are in the first row!"
Exit Sub
End If
currentrow = currentrow - 1
DateInput = Cells(currentrow, 1)
UserPayeeNm = Cells(currentrow, 2)
UserPayeeGrp = Cells(currentrow, 3)
Ammt = Cells(currentrow, 4)
Method = Cells(currentrow, 5)
ChqRefNo = Cells(currentrow, 6)
EntryType = Cells(currentrow, 7)
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
'Previous record code end
'Update record code
Private Sub cmdupdate_Click()
Dim Dname As Date, Uname As String, Ugroup As String, AM As Currency, Md As String, CHqnm As String, Entype As String
Dname = DateInput
Cells(currentrow, 1) = DateInput
Uname = UserPayeeNm
Cells(currentrow, 2) = UserPayeeNm
Ugroup = UserPayeeGrp
Cells(currentrow, 3) = UserPayeeGrp
AM = Ammt
Cells(currentrow, 4) = Ammt
'Format Input for currency and numbers
Range("D2:D10000").Select
With Selection
Ammt = Format(Ammt, "#,##0.00")
.value = .value
End With
Md = Method
Cells(currentrow, 5) = Method
CHqnm = ChqRefNo
Cells(currentrow, 6) = ChqRefNo
Entype = EntryType
Cells(currentrow, 7) = EntryType
End Sub
'Update record code end
Here is an image of the user form:
Any help appreciated.
Subbie