PREVENTING LISTBOX SELECTION FROM REVERTING BACK TO FIRST ITEM IN ROWSOURCE WHEN USERFORM LOSES AND REGAINS FOCUS

chazrab

Well-known Member
Joined
Oct 21, 2006
Messages
884
Office Version
  1. 365
Platform
  1. Windows
Title explains issue. I just want to create a simple bookmark for a textbox with a large amount of text
that will enable returning to the same point (in this case verse) Last left. If the focus is lost when another ruserform
opens, or if the userform is closed and opens back up, Excel always moves to the first item in the Listbox and the Textbox
displays the first item at the top instead of where the user left off.

If a chapter of text has 48 verses, why should the user be forced to start from the first item in the Listbox every time?
and scroll all the way down to verse 35, or 40 or 42?

To me, the code to do this correctly(leave and return to the same spot left) should be in either the navigation button or the Listbox Change event..
My code for both:
Code:
Private Sub cmdNEXT_Click()
Dim count As Integer
Dim n As Long
Dim LastRow As Long
n = BIBLETEXTWINDOW.ListBox1.ListIndex
LastRow = Sheets("RESULT").Cells(Rows.count, "B").End(xlUp).Offset(-1, 0).Row
If BIBLETEXTWINDOW.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.TextBox8.value
Set rng = Sheets("RESULT").Columns("B:B").Find(What:=verse, _
LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
Sheets("RESULT").Activate
ActiveSheet.Cells(1, 1).Select
ActiveCell.value = "x"
rng.Select
rng.Offset(0, -1).value = "x"
End Sub
The "x"'s are just placeholders on verses previously read and are in col A. I figured if I could make LastRow in col A = to
Listbox1's value, each time focus is regained and the form is active it should solve the problem.

Code:
DISPLAYS WITH SPACES BETWEEN VERSES IN A TEXTBOX 
Private Sub ListBox1_Click()
Dim n As Long
n = ListBox1.ListIndex
TextBox1.value = ListBox1.List(n, 1) _
& vbCrLf _
& vbCrLf _
& ListBox1.List(n + 1, 1) _
& vbCrLf _
& vbCrLf _
& vbCrLf + ListBox1.List(n + 2, 1) _
& vbCrLf _
& vbCrLf + ListBox1.List(n + 3, 1) _
& vbCrLf + ListBox1.List(n + 4, 1) _
& vbCrLf _
& vbCrLf + ListBox1.List(n + 5, 1) _
& vbCrLf _
& vbCrLf + ListBox1.List(n + 7, 1) _
& vbCrLf + ListBox1.List(n + 8, 1) _
& vbCrLf _
& vbCrLf + ListBox1.List(n + 9, 1) _
& vbCrLf + ListBox1.List(n + 10, 1) _

This has been a struggle for me which should be an easily solvable  solution.
I just can't connect the dots to make it works as explained.
I'm not into submitting long code or a diatrible of needless rambling.  But in order
for someone with greater understanding, I felt the picture needed to be explained 
thoroughly (images below. hopefully will shed more light)



Private Sub ListBox1_Change()
Dim n As Long
n = Me.ListBox1.ListIndex
Textbox12.value = n
BIBLENOTE.TextBox1.value = Me.ListBox1.List(n, 5)
Me.TextBox10.value = ListBox1.List(n, 5)
Me.TextBox1.value = Me.ListBox1.List(n, 2)





Me.NIV.value = Me.ListBox1.List(n, 3)
Me.NASB.value = Me.ListBox1.List(n, 4)
Me.RSV.value = Me.ListBox1.List(n, 5)
Me.TextBox8.value = ListBox1.List(n, 0)
If TextBox10.value <> "" Then 'If BIBLENOTE.TextBox1.Value <> "" Then
    TextBox10.Visible = True
     Me.TextBox11.Visible = True '(display reduced size of RESULT sheet) 'False
    TextBox11.Height = 248
    TextBox11.Top = 187
     TextBox10.Height = 139
Else
    TextBox11.Height = 393
    TextBox11.Top = 38
End If
End Sub
Rowsource = RESULT!B1:G500. This changes with each chapter.
Sorry for the long post. Thanks for anyone's help. This seems simple enough. Just can't make it work.
cr
 

Attachments

  • NEXT BUTTON MOVES TO DAN 5.jpg
    NEXT BUTTON MOVES TO DAN 5.jpg
    166.2 KB · Views: 10
  • INITIAL POSTION BEFORE ANY USER INTERACTION.png
    INITIAL POSTION BEFORE ANY USER INTERACTION.png
    94.5 KB · Views: 9

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,215,069
Messages
6,122,951
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top