As astated. I've toyed painfully with this concept for years and came up with this rather clumsy code.
The problem with this code is that sometimes it works and sometimes it doesn't If any code is perfect it should work right all the itme.
Briefly,, what this code does is put an "x" in column A of every row the next code button advances to. When the file is saved and the app
exited, upon reopening it, it should place the last row with a x in column A at the top of the userform textbox, when the user enters the Textbox with an
Enter Event or Mousedown Event, advancing down the row exiting, and returning and doing the same thing over and over if it works correctly
and so on.
Rows are displayed in a Textbox1 through Listbox1's Rowsource Property. The Change Event comes into play and its code is
When the user Enters the Textbox this code does things:
I know this ia a lot of code to look at. I did not want to leave anything out. Some of this
may be redundant and unnecessary. I'm just trying to get it to work right because I've got to
do this for 4 Textboxes and 4 Listboxes.
Any help to refine this would be greatly apprecited.
cr
Code:
Private Sub cmdNEXT_Click()
Dim count As Integer
Dim n As Long
Dim lastrow As Long
n = ALLVIEWSTB.ListBox1.ListIndex
lastrow = Sheets("ALLVIEWS1").Cells(rows.count, "B").End(xlUp).Offset(-1, 0).Row
If ALLVIEWSTB.ListBox1.ListIndex = lastrow Then
MsgBox "At last row"
Exit Sub
Else
n = Me.ListBox1.ListCount - 1
Select Case Me.ListBox1.ListIndex
Case Is < n
Me.ListBox1.ListIndex = Me.ListBox1.ListIndex + 1
Case Else
Me.ListBox1.ListIndex = 0
End Select
End If
Dim rng As Range
Dim Verse As String
Dim r As Long
Verse = Me.ListBox1.Value 'Me.TextBox3.Value
Set rng = Sheets("ALLVIEWS1").Columns("B:B").FIND(What:=Verse, _
LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
Sheets("ALLVIEWS1").Activate
ActiveSheet.Cells(1, 1).Value = "x"
'rng.Select
rng.Offset(0, -1).Value = "x"
Briefly,, what this code does is put an "x" in column A of every row the next code button advances to. When the file is saved and the app
exited, upon reopening it, it should place the last row with a x in column A at the top of the userform textbox, when the user enters the Textbox with an
Enter Event or Mousedown Event, advancing down the row exiting, and returning and doing the same thing over and over if it works correctly
and so on.
Rows are displayed in a Textbox1 through Listbox1's Rowsource Property. The Change Event comes into play and its code is
Code:
Private Sub ListBox1_Change()
Dim n As Long
n = Me.ListBox1.ListIndex
ListBox1.ListIndex = n
rowno1 = ListBox1.ListIndex + 1
End Sub
When the user Enters the Textbox this code does things:
Code:
Private Sub TextBox1_Enter()
Dim lastrow As Long, s As String, r As Range
Dim n As Integer
lastrow = Sheets("ALLVIEWS1").Range("A" & rows.count).End(xlUp).Row
ListBox1.ListIndex = lastrow - 1
Me.Textbox1.SelStart = 0
End Sub
Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
Dim lastrow As Long, s As String, r As Range
Dim n As Integer
lastrow = Sheets("ALLVIEWS1").Range("A" & rows.count).End(xlUp).Row
ListBox1.ListIndex = lastrow - 1
Me.Textbox1.SelStart = 0
Me.rowno1.Visible = True
Me.totrows1.Visible = True
ALLVIEWSTB.number = "1"
Textbox1.SelStart = 0
Textbox1.SetFocus
Textbox1.CurLine = 0
I know this ia a lot of code to look at. I did not want to leave anything out. Some of this
may be redundant and unnecessary. I'm just trying to get it to work right because I've got to
do this for 4 Textboxes and 4 Listboxes.
Any help to refine this would be greatly apprecited.
cr