View Full Version : Solved: DoubleClick event in a textbox
Rayman
06-30-2011, 05:20 AM
Here i am again..looking for help
I have this code that works fine and , on the double click , fill the textbox whit the text find in the last row of a column in a sheet.
It is possible to make a code so that for each double click in textbox this is filled with the previous text find in sheet?
Private Sub TxtDescrizioneLavori_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim numrigaCantieri As Integer
Dim UltimaDescrizione
With ActiveSheet
numrigaCantieri = Cells(Rows.Count, 15).End(xlUp).Row
UltimaDescrizione = Cells(numrigaCantieri, 15).Text
If numrigaCantieri > 3 Then
TxtDescrizioneLavori = UltimaDescrizione
End If
End With
End Sub
Hope you can understand despite my poor english.
Thanks in advance
p45cal
06-30-2011, 10:07 AM
try something messy like this (in haste):
Private Sub TxtDescrizioneLavori_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim numrigaCantieri As Integer
Dim UltimaDescrizione
Static LastRowUsed As Long
With ActiveSheet
numrigaCantieri = Cells(Rows.Count, 15).End(xlUp).Row
UltimaDescrizione = Cells(numrigaCantieri, 15).Text
If numrigaCantieri > 3 Then
If LastRowUsed < 4 Then
TxtDescrizioneLavori = UltimaDescrizione
LastRowUsed = numrigaCantieri
Else
TxtDescrizioneLavori = Cells(LastRowUsed - 1, 15).Text
LastRowUsed = LastRowUsed - 1
End If
End If
End With
End Sub
Rayman
06-30-2011, 11:57 AM
try something messy like this (in haste):
Private Sub TxtDescrizioneLavori_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim numrigaCantieri As Integer
Dim UltimaDescrizione
Static LastRowUsed As Long
With ActiveSheet
numrigaCantieri = Cells(Rows.Count, 15).End(xlUp).Row
UltimaDescrizione = Cells(numrigaCantieri, 15).Text
If numrigaCantieri > 3 Then
If LastRowUsed < 4 Then
TxtDescrizioneLavori = UltimaDescrizione
LastRowUsed = numrigaCantieri
Else
TxtDescrizioneLavori = Cells(LastRowUsed - 1, 15).Text
LastRowUsed = LastRowUsed - 1
End If
End If
End With
End Sub
Many thanks P45cal, your code work perfectly, the only problem is that not all the cells in column 15 are fill with text , then the double click load in the text box the empty value and i dont want this.
Its possible to skip empty cells?
Thanks again
p45cal
06-30-2011, 12:51 PM
Still very messy:
Private Sub TxtDescrizioneLavori_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim numrigaCantieri As Integer
Dim UltimaDescrizione
Static LastRowUsed As Long
With ActiveSheet
numrigaCantieri = Cells(Rows.Count, 15).End(xlUp).Row
UltimaDescrizione = Cells(numrigaCantieri, 15).Text
If numrigaCantieri > 3 Then
If LastRowUsed < 4 Then
TxtDescrizioneLavori = UltimaDescrizione
LastRowUsed = numrigaCantieri
Else
If Cells(LastRowUsed - 1, 15).Text <> "" Then
TxtDescrizioneLavori = Cells(LastRowUsed - 1, 15).Text
LastRowUsed = LastRowUsed - 1
Else
xx = Cells(LastRowUsed - 1, 15).End(xlUp).Row
TxtDescrizioneLavori = Cells(xx, 15).Text
LastRowUsed = xx
End If
End If
End If
End With
End Sub
Rayman
06-30-2011, 01:04 PM
Still very messy:
Private Sub TxtDescrizioneLavori_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim numrigaCantieri As Integer
Dim UltimaDescrizione
Static LastRowUsed As Long
With ActiveSheet
numrigaCantieri = Cells(Rows.Count, 15).End(xlUp).Row
UltimaDescrizione = Cells(numrigaCantieri, 15).Text
If numrigaCantieri > 3 Then
If LastRowUsed < 4 Then
TxtDescrizioneLavori = UltimaDescrizione
LastRowUsed = numrigaCantieri
Else
If Cells(LastRowUsed - 1, 15).Text <> "" Then
TxtDescrizioneLavori = Cells(LastRowUsed - 1, 15).Text
LastRowUsed = LastRowUsed - 1
Else
xx = Cells(LastRowUsed - 1, 15).End(xlUp).Row
TxtDescrizioneLavori = Cells(xx, 15).Text
LastRowUsed = xx
End If
End If
End If
End With
End Sub
Perfect, P45cal
I cannot think what you are capable to do if its not " messy":beerchug:
Many thanks and good evening
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.