• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Show text one by one in textbox with spinbutton

Visor

Member
Dear friends of the forum, forgive for maybe my bad writing in English.
I would like to know how I can do so that textbox1 shows me one by one the text of each corresponding row after having selected with double click in the listview.
For example, when selecting the first row in the listview, you should show me K15 if I click on the spinbutton it should show me L15; M15 ..... until there is text (cell occupied)
I hope you can help me,
I was very grateful in advance
upload file
 

Attachments

  • Visualizar contenido consecutivo de celdas en textbox.xlsm
    32.6 KB · Views: 8
In general I'd advise against using "ListView" object. Since it's not part of standard VBA library.

Is there any particular reason you need ListView instead of Listbox?
 
Try:
Code:
Private Sub SpinButton1_Change()
vfl = Me.ListView1.SelectedItem.Index + 14
Me.TextBox1 = Hoja2.Cells(vfl, Me.SpinButton1.Value + 11)
End Sub

Private Sub ListView1_DblClick()
vfl = Me.ListView1.SelectedItem.Index + 14
Me.TextBox1 = Hoja2.Cells(vfl, Me.SpinButton1.Value + 11)
'Hoja2.Cells(vfl, "K") = Me.TextBox1
End Sub
but note that in Private Sub SpinButton1_Change() your code uses .SelectedItem which means that if the user selects a different item in the listview, say with a single click, from that item previously double-clicked upon, the textbox will show data from that row, not the double-clicked row.
 
Thank you for your prompt response, .. this is great!

"Is there any particular reason you need ListView instead of Listbox?"

Yes, my interest in the listview is because I see that in this type of control, I manage to make items change in different color according to the approach to a date, serving as an alert and this can not be achieved in a listbox

p45Cal :As for the solution that you have given me,...
when moving with the spin button start in column K and advance beyond the last cell with data, as you should do to always reach the maximum cell with data and not allow more higher movement.
In the macro you should have noticed that I have an instruction to add text, moving the cells to the right, therefore the data in the K column will always be the most current and therefore the last cell with data will also have been moved to a next column

min: cells in column K
max: last cell with data -> msg "End, no more data"
 
I'm not going to give you a turnkey solution - it would take too long, especially as I'm uncertain of your intentions, so I'll give snippets.
For adjusting the .Max of the spinbutton you can use the likes of:
Code:
vfl = Me.ListView1.SelectedItem.Index + 14
lc = Hoja2.Cells(vfl, Columns.Count).End(xlToLeft).Column
With SpinButton1
  .Max = lc - 11
  .Value = Application.Min(lc - 11, .Value)
  Me.TextBox1 = Hoja2.Cells(vfl, .Value + 11)
End With
For the message when the last cell is reached you can:
Code:
Private Sub SpinButton1_SpinUp()
If SpinButton1.Value = SpinButton1.Max Then
  MsgBox "Rightmost cell"
End If
End Sub
 
EXCELlent, is very great!!!
This is how I expected
Application.Min,..... is the required code, in addition to the arrangement to make it work
I am very grateful
This topic is solved
 
Back
Top